diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index 8ad9b31a..e4d717d1 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -141,6 +141,11 @@ def find_files(path): yield os.path.join(dirpath, filename) +def find_uris(path): + for p in find_files(path): + yield path_to_uri(p) + + 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) diff --git a/tests/utils/path_test.py b/tests/utils/path_test.py index 54a9a8a4..3fdae887 100644 --- a/tests/utils/path_test.py +++ b/tests/utils/path_test.py @@ -271,6 +271,30 @@ class FindFilesTest(unittest.TestCase): self.assertEqual(self.find('.blank.mp3'), []) +class FindUrisTest(unittest.TestCase): + def find(self, value): + return list(path.find_uris(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): + uris = self.find('blank.mp3') + expected = path.path_to_uri(path_to_data_dir('blank.mp3')) + self.assertEqual(len(uris), 1) + self.assert_(uris[0], expected) + + def test_ignores_hidden_dirs(self): + self.assertEqual(self.find('.hidden'), []) + + def test_ignores_hidden_files(self): + self.assertEqual(self.find('.blank.mp3'), []) + + +# TODO: kill this in favour of just os.path.getmtime + mocks class MtimeTest(unittest.TestCase): def tearDown(self): path.mtime.undo_fake()