Skip to content

Commit 2cabfe9

Browse files
author
ShresthSamyak
committed
test(macos): add test coverage for CoreFoundation init fallback
1 parent 69f627e commit 2cabfe9

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

tests/test_mpv.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,3 +1069,44 @@ def test_macos_wait_for_future_timeout(self):
10691069
finally:
10701070
mpv._core_foundation = orig_cf
10711071
mpv._cf_runloop_default_mode = orig_mode
1072+
1073+
@mock.patch('sys.platform', 'darwin')
1074+
def test_macos_wait_for_future_fallback(self):
1075+
future = Future()
1076+
1077+
with mock.patch('threading.current_thread') as mock_current_thread, \
1078+
mock.patch('threading.main_thread') as mock_main_thread, \
1079+
mock.patch('ctypes.cdll.LoadLibrary') as mock_load_library, \
1080+
mock.patch('ctypes.util.find_library') as mock_find_library, \
1081+
mock.patch('ctypes.c_void_p.in_dll') as mock_in_dll:
1082+
1083+
sentinel = object()
1084+
mock_current_thread.return_value = sentinel
1085+
mock_main_thread.return_value = sentinel
1086+
1087+
# Force CoreFoundation init to fail
1088+
mock_load_library.side_effect = OSError("Library not found")
1089+
1090+
orig_cf = mpv._core_foundation
1091+
orig_mode = mpv._cf_runloop_default_mode
1092+
mpv._core_foundation = None
1093+
mpv._cf_runloop_default_mode = None
1094+
1095+
def resolve_future():
1096+
time.sleep(0.1)
1097+
try:
1098+
future.set_result('fallback_success')
1099+
except InvalidStateError:
1100+
pass
1101+
1102+
thread = threading.Thread(target=resolve_future)
1103+
thread.start()
1104+
try:
1105+
res = self.m._wait_for_future(future, timeout=1.0)
1106+
1107+
self.assertEqual(res, 'fallback_success')
1108+
self.assertFalse(mock_in_dll.called)
1109+
finally:
1110+
thread.join(timeout=1.0)
1111+
mpv._core_foundation = orig_cf
1112+
mpv._cf_runloop_default_mode = orig_mode

0 commit comments

Comments
 (0)