tests: Minor cleanup of the existing find tests
This commit is contained in:
parent
2447e2fa40
commit
de4bdbec03
@ -142,7 +142,7 @@ def _find_worker(relative, hidden, done, work, results, errors):
|
|||||||
else:
|
else:
|
||||||
errors[path] = 'Not a file or directory'
|
errors[path] = 'Not a file or directory'
|
||||||
except os.error as e:
|
except os.error as e:
|
||||||
errors[path] = str(e)
|
errors[path] = e
|
||||||
finally:
|
finally:
|
||||||
work.task_done()
|
work.task_done()
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import glib
|
|||||||
|
|
||||||
from mopidy.utils import path
|
from mopidy.utils import path
|
||||||
|
|
||||||
from tests import any_int, path_to_data_dir
|
import tests
|
||||||
|
|
||||||
|
|
||||||
class GetOrCreateDirTest(unittest.TestCase):
|
class GetOrCreateDirTest(unittest.TestCase):
|
||||||
@ -214,32 +214,35 @@ class ExpandPathTest(unittest.TestCase):
|
|||||||
class FindMTimesTest(unittest.TestCase):
|
class FindMTimesTest(unittest.TestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
||||||
def find(self, value):
|
DOES_NOT_EXIST = tests.path_to_data_dir('does-no-exist')
|
||||||
result, errors = path.find_mtimes(path_to_data_dir(value))
|
SINGLE_FILE = tests.path_to_data_dir('blank.mp3')
|
||||||
return result
|
DATA_DIR = tests.path_to_data_dir('')
|
||||||
|
FIND_DIR = tests.path_to_data_dir('find')
|
||||||
|
|
||||||
def test_basic_dir(self):
|
def test_basic_dir(self):
|
||||||
self.assert_(self.find(''))
|
result, errors = path.find_mtimes(self.DATA_DIR)
|
||||||
|
self.assert_(result)
|
||||||
|
|
||||||
def test_nonexistant_dir(self):
|
def test_nonexistant_dir(self):
|
||||||
self.assertEqual(self.find('does-not-exist'), {})
|
result, errors = path.find_mtimes(self.DOES_NOT_EXIST)
|
||||||
|
self.assertEqual(result, {})
|
||||||
|
self.assertEqual(errors, {self.DOES_NOT_EXIST: tests.IsA(OSError)})
|
||||||
|
|
||||||
def test_file(self):
|
def test_file(self):
|
||||||
self.assertEqual({path_to_data_dir('blank.mp3'): any_int},
|
result, errors = path.find_mtimes(self.SINGLE_FILE)
|
||||||
self.find('blank.mp3'))
|
self.assertEqual({self.SINGLE_FILE: tests.any_int}, result)
|
||||||
|
|
||||||
def test_files(self):
|
def test_files(self):
|
||||||
mtimes = self.find('find')
|
result, errors = path.find_mtimes(self.FIND_DIR)
|
||||||
expected_files = [
|
expected = {
|
||||||
b'find/foo/bar/file', b'find/foo/file', b'find/baz/file']
|
tests.path_to_data_dir(b'find/foo/bar/file'): tests.any_int,
|
||||||
expected = {path_to_data_dir(p): any_int for p in expected_files}
|
tests.path_to_data_dir(b'find/foo/file'): tests.any_int,
|
||||||
self.assertEqual(expected, mtimes)
|
tests.path_to_data_dir(b'find/baz/file'): tests.any_int}
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
def test_names_are_bytestrings(self):
|
def test_names_are_bytestrings(self):
|
||||||
is_bytes = lambda f: isinstance(f, bytes)
|
for name in path.find_mtimes(self.DATA_DIR)[0]:
|
||||||
for name in self.find(''):
|
self.assertEqual(name, tests.IsA(bytes))
|
||||||
self.assert_(
|
|
||||||
is_bytes(name), '%s is not bytes object' % repr(name))
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: kill this in favour of just os.path.getmtime + mocks
|
# TODO: kill this in favour of just os.path.getmtime + mocks
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user