Skip to content

Commit 9bf95bf

Browse files
committed
Some test code cleanup for #1586
1 parent 3b604c7 commit 9bf95bf

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

test/test_query.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -509,35 +509,39 @@ def test_case_sensitivity(self):
509509
self.assert_items_matched(results, ['path item', 'caps path'])
510510

511511
# Check for correct case sensitivity selection (this check
512-
# only works for non-windows os)
512+
# only works on non-Windows OSes).
513513
with _common.system_mock('Darwin'):
514514
# exists = True and samefile = True => Case insensitive
515515
q = makeq()
516516
self.assertEqual(q.case_sensitive, False)
517517

518-
self.patcher_samefile.stop()
519-
self.patcher_samefile.start().return_value = False
520-
521518
# exists = True and samefile = False => Case sensitive
522-
q = makeq()
523-
self.assertEqual(q.case_sensitive, True)
524-
525519
self.patcher_samefile.stop()
526-
self.patcher_samefile.start().return_value = True
520+
self.patcher_samefile.start().return_value = False
521+
try:
522+
q = makeq()
523+
self.assertEqual(q.case_sensitive, True)
524+
finally:
525+
self.patcher_samefile.stop()
526+
self.patcher_samefile.start().return_value = True
527527

528-
# test platform-aware default sensitivity when the library
529-
# path does not exist (exist = False)
528+
# Test platform-aware default sensitivity when the library path
529+
# does not exist. For the duration of this check, we change the
530+
# `os.path.exists` mock to return False.
530531
self.patcher_exists.stop()
531532
self.patcher_exists.start().return_value = False
532-
with _common.system_mock('Darwin'):
533-
q = makeq()
534-
self.assertEqual(q.case_sensitive, True)
533+
try:
534+
with _common.system_mock('Darwin'):
535+
q = makeq()
536+
self.assertEqual(q.case_sensitive, True)
535537

536-
with _common.system_mock('Windows'):
537-
q = makeq()
538-
self.assertEqual(q.case_sensitive, False)
539-
self.patcher_exists.stop()
540-
self.patcher_exists.start().return_value = True
538+
with _common.system_mock('Windows'):
539+
q = makeq()
540+
self.assertEqual(q.case_sensitive, False)
541+
finally:
542+
# Restore the `os.path.exists` mock to its original state.
543+
self.patcher_exists.stop()
544+
self.patcher_exists.start().return_value = True
541545

542546
@patch('beets.library.os')
543547
def test_path_sep_detection(self, mock_os):

0 commit comments

Comments
 (0)