From de4bdbec03d96ec8d5c2aeec7690e70b51325e6f Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 14 Oct 2014 22:52:41 +0200 Subject: [PATCH] tests: Minor cleanup of the existing find tests --- mopidy/utils/path.py | 2 +- tests/utils/test_path.py | 37 ++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index a9187d8f..a633a041 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -142,7 +142,7 @@ def _find_worker(relative, hidden, done, work, results, errors): else: errors[path] = 'Not a file or directory' except os.error as e: - errors[path] = str(e) + errors[path] = e finally: work.task_done() diff --git a/tests/utils/test_path.py b/tests/utils/test_path.py index 51dad2cb..fa2972fd 100644 --- a/tests/utils/test_path.py +++ b/tests/utils/test_path.py @@ -11,7 +11,7 @@ import glib from mopidy.utils import path -from tests import any_int, path_to_data_dir +import tests class GetOrCreateDirTest(unittest.TestCase): @@ -214,32 +214,35 @@ class ExpandPathTest(unittest.TestCase): class FindMTimesTest(unittest.TestCase): maxDiff = None - def find(self, value): - result, errors = path.find_mtimes(path_to_data_dir(value)) - return result + DOES_NOT_EXIST = tests.path_to_data_dir('does-no-exist') + SINGLE_FILE = tests.path_to_data_dir('blank.mp3') + DATA_DIR = tests.path_to_data_dir('') + FIND_DIR = tests.path_to_data_dir('find') 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): - 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): - self.assertEqual({path_to_data_dir('blank.mp3'): any_int}, - self.find('blank.mp3')) + result, errors = path.find_mtimes(self.SINGLE_FILE) + self.assertEqual({self.SINGLE_FILE: tests.any_int}, result) 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) + result, errors = path.find_mtimes(self.FIND_DIR) + expected = { + tests.path_to_data_dir(b'find/foo/bar/file'): tests.any_int, + tests.path_to_data_dir(b'find/foo/file'): tests.any_int, + tests.path_to_data_dir(b'find/baz/file'): tests.any_int} + self.assertEqual(expected, result) 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)) + for name in path.find_mtimes(self.DATA_DIR)[0]: + self.assertEqual(name, tests.IsA(bytes)) # TODO: kill this in favour of just os.path.getmtime + mocks