From de5fe5ebab40aedca5566777f5bc7a56f8b529a9 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 14 Oct 2014 23:51:57 +0200 Subject: [PATCH] tests: Add test for current find symlink handling --- mopidy/utils/path.py | 2 +- tests/data/find2/bar | 1 + tests/data/find2/foo | 0 tests/utils/test_path.py | 9 ++++++++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 120000 tests/data/find2/bar create mode 100644 tests/data/find2/foo diff --git a/mopidy/utils/path.py b/mopidy/utils/path.py index a633a041..0730fa06 100644 --- a/mopidy/utils/path.py +++ b/mopidy/utils/path.py @@ -140,7 +140,7 @@ def _find_worker(relative, hidden, done, work, results, errors): elif stat.S_ISREG(st.st_mode): results[path] = st else: - errors[path] = 'Not a file or directory' + errors[path] = Exception('Not a file or directory') except os.error as e: errors[path] = e finally: diff --git a/tests/data/find2/bar b/tests/data/find2/bar new file mode 120000 index 00000000..19102815 --- /dev/null +++ b/tests/data/find2/bar @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/tests/data/find2/foo b/tests/data/find2/foo new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils/test_path.py b/tests/utils/test_path.py index f19b337b..19573003 100644 --- a/tests/utils/test_path.py +++ b/tests/utils/test_path.py @@ -216,11 +216,13 @@ class FindMTimesTest(unittest.TestCase): DOES_NOT_EXIST = tests.path_to_data_dir('does-no-exist') SINGLE_FILE = tests.path_to_data_dir('blank.mp3') + SINGLE_SYMLINK = tests.path_to_data_dir('find2/bar') DATA_DIR = tests.path_to_data_dir('') FIND_DIR = tests.path_to_data_dir('find') + FIND2_DIR = tests.path_to_data_dir('find2') def test_basic_dir(self): - result, errors = path.find_mtimes(self.DATA_DIR) + result, errors = path.find_mtimes(self.FIND_DIR) self.assert_(result) self.assertEqual(errors, {}) @@ -247,6 +249,11 @@ class FindMTimesTest(unittest.TestCase): for name in path.find_mtimes(self.DATA_DIR)[0]: self.assertEqual(name, tests.IsA(bytes)) + def test_symlinks_are_ignored(self): + result, errors = path.find_mtimes(self.SINGLE_SYMLINK) + self.assertEqual({}, result) + self.assertEqual({self.SINGLE_SYMLINK: tests.IsA(Exception)}, errors) + # TODO: kill this in favour of just os.path.getmtime + mocks class MtimeTest(unittest.TestCase):