@@ -509,35 +509,39 @@ def test_case_sensitivity(self):
509
509
self .assert_items_matched (results , ['path item' , 'caps path' ])
510
510
511
511
# Check for correct case sensitivity selection (this check
512
- # only works for non-windows os)
512
+ # only works on non-Windows OSes).
513
513
with _common .system_mock ('Darwin' ):
514
514
# exists = True and samefile = True => Case insensitive
515
515
q = makeq ()
516
516
self .assertEqual (q .case_sensitive , False )
517
517
518
- self .patcher_samefile .stop ()
519
- self .patcher_samefile .start ().return_value = False
520
-
521
518
# exists = True and samefile = False => Case sensitive
522
- q = makeq ()
523
- self .assertEqual (q .case_sensitive , True )
524
-
525
519
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
527
527
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.
530
531
self .patcher_exists .stop ()
531
532
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 )
535
537
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
541
545
542
546
@patch ('beets.library.os' )
543
547
def test_path_sep_detection (self , mock_os ):
0 commit comments