Skip to content

Commit a7f7278

Browse files
author
ShresthSamyak
committed
fix(macos): address PR review comments from Copilot
1 parent 1bcb5ab commit a7f7278

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

mpv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def update(self, filename=None, size=None, stride=None, pos=None):
842842
w, h = self.size # type: ignore
843843
stride = self.stride or 4*w
844844

845-
self.m.overlay_add(self, self.overlay_id, x, y, self.filename, 0, 'bgra', w, h, stride) # pyre-ignore
845+
self.m.overlay_add(self.overlay_id, x, y, self.filename, 0, 'bgra', w, h, stride) # pyre-ignore
846846

847847
def remove(self):
848848
self.m.remove_overlay(self.overlay_id)
@@ -1115,6 +1115,8 @@ def observer(name, val):
11151115
except:
11161116
pass
11171117

1118+
err_unregister = lambda: None
1119+
11181120
try:
11191121
result.set_running_or_notify_cancel()
11201122

tests/test_mpv.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)