Issue2549

classification
Title: test_posix fails on Linux
Type: behaviour Severity: normal
Components: Versions: Jython 2.7
Milestone:
process
Status: pending Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: stefan.richthofer
Priority: normal Keywords:

Created on 2017-02-07.15:12:15 by stefan.richthofer, last changed 2017-02-07.16:58:28 by stefan.richthofer.

Messages
msg11079 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-07.15:12:14
======================================================================
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?
msg11080 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-07.16:58:28
To move things forward I just applied c) as of
https://github.com/jythontools/jython/commit/07ff417835c23bd584c923be3c6a758c02261805
and
https://github.com/jythontools/jython/commit/0a4d63c62620f5b1e3026237fd40dfbf70b3cf9d

In case there come up striking points for a) or b) (or "d)") it won't be a big deal to switch stuff accordingly.
History
Date User Action Args
2017-02-07 16:58:28stefan.richthofersetstatus: open -> pending
assignee: stefan.richthofer
resolution: fixed
messages: + msg11080
2017-02-07 15:12:15stefan.richthofercreate