openSUSE / osc2

The next Command Line Interface to work with an openSUSE Build Service
http://openbuildservice.org/
17 stars 9 forks source link

Float number comparison in cpio test #2

Closed bhdn closed 11 years ago

bhdn commented 11 years ago

posix.stat_result has a higher precision than AsciiReader header's, resulting in a test failling because of a difference smaller than 0.5 second.

marcus-h commented 11 years ago

Hmm I'm not quite sure if the fix is correct because it is possible that abs(hdr.mtime - st.st_mtime) > 0.5. IMHO the "correct" fix is to use something like: self.assertEqual(hdr.mtime, int(st.st_mtime)) because hdr.mtime == floor(st.st_mtime) should always hold.

Can you post the exact error message you get without your patch?

bhdn commented 11 years ago

Indeed, converting it to int() seems to be better. I thought of delta=0.5 because when it exceeds 0.5 it should roll over hdr.mtime. This is the error:

Traceback (most recent call last):
  File "/home/bogdano/git/osc2/test/util/test_cpio.py", line 608, in test18
    self.assertEqual(float(hdr.mtime), st.st_mtime)
AssertionError: 1362500288.0 != 1362500288.444055
marcus-h commented 11 years ago

Fixed in commit d2b2e3aca7236305a791eac4ed8841d3fc7ffcaa. Thanks for the report!