Opened 9 years ago

Last modified 4 years ago

#6755 new bug

Python 2.7's test_os.py fails self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))

Reported by: scottmc Owned by: nobody
Priority: normal Milestone: R1
Component: System Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description (last modified by scottmc)

These appear to be Haiku related failures.

======================================================================
FAIL: test_utime_dir (__main__.StatAttributeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_os.py", line 349, in test_utime_dir
    self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
AssertionError: 1287124148.00734 != 1287124148

======================================================================
FAIL: test_ttyname (__main__.TestInvalidFD)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_os.py", line 795, in check
    f(support.make_bad_fd(), *args)
OSError: [Errno -2147454966] Not a tty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_os.py", line 788, in helper
    self.check(getattr(os, f))
  File "test_os.py", line 797, in check
    self.assertEqual(e.errno, errno.EBADF)
AssertionError: -2147454966 != -2147459072

======================================================================
FAIL: test_encodings (__main__.FSEncodingTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_os.py", line 1203, in test_encodings
    check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
  File "test_os.py", line 1192, in check
    self.assertEqual(encoded, repr(bytesfn))
AssertionError: "b'\\xc3\\xaf\\xe2\\x82\\xac'" != "b'\\xef\\xa4'"
- b'\xc3\xaf\xe2\x82\xac'
+ b'\xef\xa4'

Tests are in boot/common/lib/python2.6/test to run use "python test_os.py"

Change History (8)

comment:1 by scottmc, 9 years ago

The test_encodings failure is probably related to this one at HaikuPorts: http://ports.haiku-files.org/ticket/422

comment:2 by scottmc, 8 years ago

Description: modified (diff)
Summary: Python3's test_os.py fails 3 testsPython's test_os.py fails self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))

only 1 failure in this test now in hrev42190 alpha3-rc:

/boot/common/lib/python2.6/test> python test_os.py --verbose
test_access (__main__.FileTests) ... ok
test_closerange (__main__.FileTests) ... ok
test_rename (__main__.FileTests) ... ok
test_tempnam (__main__.TemporaryFileTests) ... ok
test_tmpfile (__main__.TemporaryFileTests) ... ok
test_tmpnam (__main__.TemporaryFileTests) ... ok
test_stat_attributes (__main__.StatAttributeTests) ... ok
test_statvfs_attributes (__main__.StatAttributeTests) ... ok
test_utime_dir (__main__.StatAttributeTests) ... FAIL
test_bool (__main__.EnvironTests) ... ok
test_constructor (__main__.EnvironTests) ... ok
test_get (__main__.EnvironTests) ... ok
test_getitem (__main__.EnvironTests) ... ok
test_items (__main__.EnvironTests) ... ok
test_keys (__main__.EnvironTests) ... ok
test_len (__main__.EnvironTests) ... ok
test_pop (__main__.EnvironTests) ... ok
test_popitem (__main__.EnvironTests) ... ok
test_read (__main__.EnvironTests) ... ok
test_setdefault (__main__.EnvironTests) ... ok
test_update (__main__.EnvironTests) ... ok
test_update2 (__main__.EnvironTests) ... ok
test_values (__main__.EnvironTests) ... ok
test_write (__main__.EnvironTests) ... ok
test_traversal (__main__.WalkTests) ... ok
test_makedir (__main__.MakedirTests) ... ok
test_devnull (__main__.DevNullTests) ... ok
test_urandom (__main__.URandomTests) ... ok
test_closerange (__main__.TestInvalidFD) ... ok
test_dup (__main__.TestInvalidFD) ... ok
test_dup2 (__main__.TestInvalidFD) ... ok
test_fchdir (__main__.TestInvalidFD) ... ok
test_fchmod (__main__.TestInvalidFD) ... ok
test_fchown (__main__.TestInvalidFD) ... ok
test_fdatasync (__main__.TestInvalidFD) ... ok
test_fdopen (__main__.TestInvalidFD) ... ok
test_fpathconf (__main__.TestInvalidFD) ... ok
test_fstat (__main__.TestInvalidFD) ... ok
test_fstatvfs (__main__.TestInvalidFD) ... ok
test_fsync (__main__.TestInvalidFD) ... ok
test_ftruncate (__main__.TestInvalidFD) ... ok
test_isatty (__main__.TestInvalidFD) ... ok
test_lseek (__main__.TestInvalidFD) ... ok
test_read (__main__.TestInvalidFD) ... ok
test_tcgetpgrp (__main__.TestInvalidFD) ... ok
test_tcsetpgrpt (__main__.TestInvalidFD) ... ok
test_ttyname (__main__.TestInvalidFD) ... ok
test_write (__main__.TestInvalidFD) ... ok
test_setegid (__main__.PosixUidGidTests) ... ok
test_seteuid (__main__.PosixUidGidTests) ... ok
test_setgid (__main__.PosixUidGidTests) ... ok
test_setregid (__main__.PosixUidGidTests) ... ok
test_setregid_neg1 (__main__.PosixUidGidTests) ... ok
test_setreuid (__main__.PosixUidGidTests) ... ok
test_setreuid_neg1 (__main__.PosixUidGidTests) ... ok
test_setuid (__main__.PosixUidGidTests) ... ok

======================================================================
FAIL: test_utime_dir (__main__.StatAttributeTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_os.py", line 298, in test_utime_dir
    self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
AssertionError: 1307218095.00367 != 1307218095

----------------------------------------------------------------------
Ran 56 tests in 84.093s

FAILED (failures=1)
Traceback (most recent call last):
  File "test_os.py", line 690, in <module>
    test_main()
  File "test_os.py", line 686, in test_main
    PosixUidGidTests
  File "/boot/common/lib/python2.6/test/test_support.py", line 820, in run_unittest
    _run_suite(suite)
  File "/boot/common/lib/python2.6/test/test_support.py", line 803, in _run_suite
    raise TestFailed(err)
test.test_support.TestFailed: Traceback (most recent call last):
  File "test_os.py", line 298, in test_utime_dir
    self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
AssertionError: 1307218095.00367 != 1307218095

/boot/common/lib/python2.6/test> 

comment:3 by bonefish, 8 years ago

Someone familiar with python needs to have a look at those tests. In C the stat::st_mtime is an integer field. No clue where the python test gets the fraction values from. Or maybe the AssertionError is printed in reverse order and delta has a fraction part.

comment:4 by jprostko, 8 years ago

I quickly threw two lines into test_os.py in the time_utime_dir function and got the entire test to pass (all 56 OK). That said, I was doing that to check where things trip up, as I need to investigate more yet.

Anyway, on Haiku and most (all?) other platforms nowadays, stat_float_times returns True by default as of Python 2.5, I believe. As such, it seems the particular test comparison in question is comparing a float to an int and hence the comparison fails.

To get it to pass, I just quickly hacked in...

from os import stat_float_times
stat_float_times(False)

I want to dig into things to actually address it correctly, but just wanted to state that I have a starting point anyway. I'll try to look into it in my spare time tomorrow and over the weekend, as I want to play around on different platforms as well to see how they behave compared to us.

comment:5 by anevilyak, 8 years ago

The mtime test fails for a simple reason: BFS intentionally salts the tv_nsec field in order to generate a more unique distribution for its last_modified index. Consequently, the nsec field passed in will more or less never match the one that ultimately winds up being written to disk. c.f. browser:haiku/trunk/src/add-ons/kernel/file_systems/bfs/bfs.h#L237

comment:6 by axeld, 8 years ago

While BFS behaviour is rather stupid, or let's say legacy, I would argue that the test is broken, as most file systems do not support a resolution better than one second, even if the operating system does support m_tim. IOW it cannot rely to get the same value back (well, at least if non-zero).

comment:7 by dsizzle, 4 years ago

For this line: self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))

...if we're casting the second argument to int, why not just cast the first to int as well?

self.assertEquals(int(st2.st_mtime), int(st.st_mtime-delta))

that doesn't seem to break the spirit of the test in my opinion...if st2.st_mtime is returning a float then comparing to an int expression is *never* going to work anyway.

comment:8 by korli, 4 years ago

Summary: Python's test_os.py fails self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))Python 2.7's test_os.py fails self.assertEquals(st2.st_mtime, int(st.st_mtime-delta))
Note: See TracTickets for help on using tickets.