util: Add find_mtimes helper
This commit is contained in:
parent
4e332da3ed
commit
5b7a6065e7
@ -200,6 +200,11 @@ def find_files(path):
|
||||
return results.iterkeys()
|
||||
|
||||
|
||||
def find_mtimes(root):
|
||||
results, errors = _find(root, hidden=False, relative=False)
|
||||
return dict((f, int(st.st_mtime)) for f, st in results.iteritems())
|
||||
|
||||
|
||||
def check_file_path_is_inside_base_dir(file_path, base_path):
|
||||
assert not file_path.endswith(os.sep), (
|
||||
'File path %s cannot end with a path separator' % file_path)
|
||||
|
||||
@ -11,7 +11,7 @@ import glib
|
||||
|
||||
from mopidy.utils import path
|
||||
|
||||
from tests import path_to_data_dir
|
||||
from tests import any_int, path_to_data_dir
|
||||
|
||||
|
||||
class GetOrCreateDirTest(unittest.TestCase):
|
||||
@ -235,6 +235,36 @@ class FindFilesTest(unittest.TestCase):
|
||||
is_bytes(name), '%s is not bytes object' % repr(name))
|
||||
|
||||
|
||||
class FindMTimesTest(unittest.TestCase):
|
||||
maxDiff = None
|
||||
|
||||
def find(self, value):
|
||||
return path.find_mtimes(path_to_data_dir(value))
|
||||
|
||||
def test_basic_dir(self):
|
||||
self.assert_(self.find(''))
|
||||
|
||||
def test_nonexistant_dir(self):
|
||||
self.assertEqual(self.find('does-not-exist'), {})
|
||||
|
||||
def test_file(self):
|
||||
self.assertEqual({path_to_data_dir('blank.mp3'): any_int},
|
||||
self.find('blank.mp3'))
|
||||
|
||||
def test_files(self):
|
||||
mtimes = self.find('find')
|
||||
expected_files = [
|
||||
b'find/foo/bar/file', b'find/foo/file', b'find/baz/file']
|
||||
expected = {path_to_data_dir(p): any_int for p in expected_files}
|
||||
self.assertEqual(expected, mtimes)
|
||||
|
||||
def test_names_are_bytestrings(self):
|
||||
is_bytes = lambda f: isinstance(f, bytes)
|
||||
for name in self.find(''):
|
||||
self.assert_(
|
||||
is_bytes(name), '%s is not bytes object' % repr(name))
|
||||
|
||||
|
||||
# TODO: kill this in favour of just os.path.getmtime + mocks
|
||||
class MtimeTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user