tests: fix test breakage due to promotion from int to long
This fixes #1240. In internals/path.py. there is a snippet of code that multiples mtime for a file with 1000, and then casting it to `int`, to return the number of milliseconds since epoch (or whatever). This will, however, not ensure that the result is an `int`. >>> type(int(2**32)) <type 'long'> Instead, fix the tests to look for (int, long), and clarify the implementation. This bug found on a 32-bit VM :)
This commit is contained in:
parent
2b06b77865
commit
1eb41aca7d
@ -192,7 +192,8 @@ def _find(root, thread_count=10, relative=False, follow=False):
|
|||||||
|
|
||||||
def find_mtimes(root, follow=False):
|
def find_mtimes(root, follow=False):
|
||||||
results, errors = _find(root, relative=False, follow=follow)
|
results, errors = _find(root, relative=False, follow=follow)
|
||||||
mtimes = dict((f, int(st.st_mtime * 1000)) for f, st in results.items())
|
# return the mtimes as integer milliseconds
|
||||||
|
mtimes = {f: int(st.st_mtime * 1000) for f, st in results.items()}
|
||||||
return mtimes, errors
|
return mtimes, errors
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,6 @@ class IsA(object):
|
|||||||
return str(self.klass)
|
return str(self.klass)
|
||||||
|
|
||||||
|
|
||||||
any_int = IsA(int)
|
any_int = IsA((int, long))
|
||||||
any_str = IsA(str)
|
any_str = IsA(str)
|
||||||
any_unicode = IsA(compat.text_type)
|
any_unicode = IsA(compat.text_type)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ class PlaybackHistoryTest(unittest.TestCase):
|
|||||||
result = self.history.get_history()
|
result = self.history.get_history()
|
||||||
(timestamp, ref) = result[0]
|
(timestamp, ref) = result[0]
|
||||||
|
|
||||||
self.assertIsInstance(timestamp, int)
|
self.assertIsInstance(timestamp, (int, long))
|
||||||
self.assertEqual(track.uri, ref.uri)
|
self.assertEqual(track.uri, ref.uri)
|
||||||
self.assertIn(track.name, ref.name)
|
self.assertIn(track.name, ref.name)
|
||||||
for artist in track.artists:
|
for artist in track.artists:
|
||||||
|
|||||||
@ -380,6 +380,18 @@ class FindMTimesTest(unittest.TestCase):
|
|||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
self.assertEqual({}, errors)
|
self.assertEqual({}, errors)
|
||||||
|
|
||||||
|
def test_gives_mtime_in_milliseconds(self):
|
||||||
|
fname = self.touch('foobar')
|
||||||
|
|
||||||
|
os.utime(fname, (1, 3.14159265))
|
||||||
|
|
||||||
|
result, errors = path.find_mtimes(fname)
|
||||||
|
|
||||||
|
self.assertEqual(len(result), 1)
|
||||||
|
mtime, = result.values()
|
||||||
|
self.assertEqual(mtime, 3141)
|
||||||
|
self.assertEqual(errors, {})
|
||||||
|
|
||||||
|
|
||||||
# TODO: kill this in favour of just os.path.getmtime + mocks
|
# TODO: kill this in favour of just os.path.getmtime + mocks
|
||||||
class MtimeTest(unittest.TestCase):
|
class MtimeTest(unittest.TestCase):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user