path: Add find_uris version of find_files
This commit is contained in:
parent
f91e621c40
commit
351589c6c8
@ -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)
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user