Message11079

Author stefan.richthofer
Recipients stefan.richthofer
Date 2017-02-07.15:12:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486480335.76.0.220241733092.issue2549@psf.upfronthosting.co.za>
In-reply-to
Content
======================================================================
FAIL: test_stat_tuple (__main__.PosixTester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_posix.py", line 221, in test_stat_tuple
    self.assertEqual(tuple(posix.stat(".")), posix.stat("."))
AssertionError: (16895, 25766, 2056L, 1, 1000, 0, 16384, 1486335343.872158, 1486475914.163193, 1486475914.163193) != posix.stat_result(st_mode=16895, st_ino=25766, st_dev=2056L, st_nlink=1, st_uid=1000, st_gid=0, st_size=16384, st_atime=1486335343, st_mtime=1486475914, st_ctime=1486475914)

----------------------------------------------------------------------
Ran 33 tests in 0.094s

FAILED (failures=1, skipped=9)
Traceback (most recent call last):
  File "Lib/test/test_posix.py", line 472, in <module>
    test_main()
  File "Lib/test/test_posix.py", line 469, in test_main
    test_support.run_unittest(PosixTester, PosixGroupsTester)
  File "/data/workspace/linux/Jython/stewori/jython/dist/Lib/test/test_support.py", line 1320, in run_unittest
    _run_suite(suite)
  File "/data/workspace/linux/Jython/stewori/jython/dist/Lib/test/test_support.py", line 1303, in _run_suite
    raise TestFailed(err)
test.test_support.TestFailed: Traceback (most recent call last):
  File "Lib/test/test_posix.py", line 221, in test_stat_tuple
    self.assertEqual(tuple(posix.stat(".")), posix.stat("."))
AssertionError: (16895, 25766, 2056L, 1, 1000, 0, 16384, 1486335343.872158, 1486475914.163193, 1486475914.163193) != posix.stat_result(st_mode=16895, st_ino=25766, st_dev=2056L, st_nlink=1, st_uid=1000, st_gid=0, st_size=16384, st_atime=1486335343, st_mtime=1486475914, st_ctime=1486475914)

This is because PyStatResult halfheartedly stores times as floats. Its pyget implementation converts times to PyInt on the fly, but tuple-convertion works via iterator, which doesn't use pyget.

So there are several solutions:

a) store times actually as int (or long?), i.e. change lines like

Py.newFloat(fromFileTime((FileTime)stat.get("lastAccessTime"))),
to Py.newInteger((int) fromFileTime((FileTime)stat.get("lastAccessTime"))),

In that case pyget can be removed in PyStatResult (i.e. left to the superclass)


b) Go consistently the PyFloat-path, i.e. only remove pyget, so floats stay floats also for cmp.


c) Anyway it stores every value twice: Once in its superclass' tuple-array and once in named fields. We could store PyInteger-times in the tuple and PyFloat times in the named fields.
Thi would be achieved by changing the constructor's first line from
super(TYPE, vals);
to
super(TYPE, new PyObject[] {vals[0], vals[1], vals[2], vals[3], vals[4], vals[5], vals[6], Py.newInteger(vals[7].asInt()), Py.newInteger(vals[8].asInt()), Py.newInteger(vals[9].asInt()) });


Each would solve the issue. CPython seems to display int times consistently, but however has an option posix.stat_float_times. On the other hand this option pretends to be true for me and I still get int times, so it's also somehow fishy in CPython.

a) would yield information-loss (no float time)
b) would differ from CPython
c) would lack some inner consistency - same value stored as int and float

Still I would slightly be for c), because it seems to be the best solution for all and it would be easy to implement posix.stat_float_times later on.

Opinions?
History
Date User Action Args
2017-02-07 15:12:15stefan.richthofersetrecipients: + stefan.richthofer
2017-02-07 15:12:15stefan.richthofersetmessageid: <1486480335.76.0.220241733092.issue2549@psf.upfronthosting.co.za>
2017-02-07 15:12:15stefan.richthoferlinkissue2549 messages
2017-02-07 15:12:14stefan.richthofercreate