@@ -990,3 +990,63 @@ def t(self, *args, **kw):
990990 m .slang = 'ru'
991991 m .terminate () # needed for synchronization of event thread
992992 handler .assert_has_calls ([mock .call ('slang' , ['jp' ]), mock .call ('slang' , ['ru' ])])
993+
994+ class TestMacOSWait (MpvTestCase ):
995+ @mock .patch ('sys.platform' , 'darwin' )
996+ def test_macos_wait_for_future (self ):
997+ future = Future ()
998+
999+ with mock .patch ('threading.current_thread' ) as mock_current_thread , \
1000+ mock .patch ('threading.main_thread' ) as mock_main_thread , \
1001+ mock .patch ('ctypes.cdll.LoadLibrary' ) as mock_load_library , \
1002+ mock .patch ('ctypes.util.find_library' ) as mock_find_library :
1003+
1004+ # Make sure threading check passes
1005+ mock_current_thread .return_value = 'main'
1006+ mock_main_thread .return_value = 'main'
1007+
1008+ # Setup CFRunLoopRunInMode mock
1009+ mock_cf = mock .Mock ()
1010+ mock_load_library .return_value = mock_cf
1011+
1012+ # Reset globals from mpv module to force re-initialization
1013+ mpv ._core_foundation = None
1014+ mpv ._cf_runloop_default_mode = None
1015+
1016+ def resolve_future ():
1017+ time .sleep (0.1 )
1018+ try :
1019+ future .set_result ('success' )
1020+ except InvalidStateError :
1021+ pass
1022+
1023+ threading .Thread (target = resolve_future ).start ()
1024+
1025+ res = self .m ._wait_for_future (future , timeout = 1.0 )
1026+
1027+ self .assertEqual (res , 'success' )
1028+ self .assertTrue (mock_cf .CFRunLoopRunInMode .called )
1029+
1030+ @mock .patch ('sys.platform' , 'darwin' )
1031+ def test_macos_wait_for_future_timeout (self ):
1032+ future = Future ()
1033+
1034+ with mock .patch ('threading.current_thread' ) as mock_current_thread , \
1035+ mock .patch ('threading.main_thread' ) as mock_main_thread , \
1036+ mock .patch ('ctypes.cdll.LoadLibrary' ) as mock_load_library , \
1037+ mock .patch ('ctypes.util.find_library' ) as mock_find_library :
1038+
1039+ mock_current_thread .return_value = 'main'
1040+ mock_main_thread .return_value = 'main'
1041+
1042+ mock_cf = mock .Mock ()
1043+ mock_load_library .return_value = mock_cf
1044+
1045+ mpv ._core_foundation = None
1046+ mpv ._cf_runloop_default_mode = None
1047+
1048+ from concurrent .futures import TimeoutError
1049+ with self .assertRaises (TimeoutError ):
1050+ self .m ._wait_for_future (future , timeout = 0.1 )
1051+
1052+ self .assertTrue (mock_cf .CFRunLoopRunInMode .called )
0 commit comments