From 58ddecf7af017b3ea7774e436a71c7ce9f096e08 Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Fri, 4 Sep 2015 18:34:43 +0200 Subject: [PATCH] Added a Patch decorator for the os.path.samefile function to repair some previously failed test cases. --- test/test_query.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/test_query.py b/test/test_query.py index 04235906d..8507eb312 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -376,12 +376,17 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin): self.i.store() self.lib.add_album([self.i]) - self.patcher = patch('beets.library.os.path.exists') - self.patcher.start().return_value = True + self.patcher_exists = patch('beets.library.os.path.exists') + self.patcher_exists.start().return_value = True + + self.patcher_samefile = patch('beets.library.os.path.samefile') + self.patcher_samefile.start().return_value = True def tearDown(self): super(PathQueryTest, self).tearDown() - self.patcher.stop() + + self.patcher_samefile.stop() + self.patcher_exists.stop() def test_path_exact_match(self): q = 'path:/a/b/c.mp3' @@ -504,13 +509,17 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin): self.assert_items_matched(results, ['path item', 'caps path']) # test platform-aware default sensitivity - with _common.system_mock('Darwin'): - q = makeq() - self.assertEqual(q.case_sensitive, True) + self.patcher_exists.stop() + try: + with _common.system_mock('Darwin'): + q = makeq() + self.assertEqual(q.case_sensitive, True) - with _common.system_mock('Windows'): - q = makeq() - self.assertEqual(q.case_sensitive, False) + with _common.system_mock('Windows'): + q = makeq() + self.assertEqual(q.case_sensitive, False) + finally: + self.patcher_exists.start() @patch('beets.library.os') def test_path_sep_detection(self, mock_os): @@ -526,7 +535,7 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin): def test_path_detection(self): # cover existence test - self.patcher.stop() + self.patcher_exists.stop() is_path = beets.library.PathQuery.is_path_query try: @@ -546,7 +555,7 @@ class PathQueryTest(_common.LibTestCase, TestHelper, AssertsMixin): finally: os.chdir(cur_dir) finally: - self.patcher.start() + self.patcher_exists.start() class IntQueryTest(unittest.TestCase, TestHelper):