复核驱动输入与窗口补丁,修复接管互斥和异常清理
This commit is contained in:
@@ -107,12 +107,51 @@ class BackgroundRestoreTest(unittest.TestCase):
|
|||||||
engine.screen = mock.Mock()
|
engine.screen = mock.Mock()
|
||||||
engine.auto.input_handler.pos_offset.return_value = (100, 200)
|
engine.auto.input_handler.pos_offset.return_value = (100, 200)
|
||||||
engine._prepare_input = mock.Mock()
|
engine._prepare_input = mock.Mock()
|
||||||
with mock.patch('pyautogui.moveTo'), mock.patch('pyautogui.mouseDown'), \
|
with mock.patch.dict(sys.modules, pyautogui=mock.Mock()), \
|
||||||
mock.patch('pyautogui.mouseUp'), \
|
|
||||||
mock.patch('lc_mcp.aalc_engine.time.sleep'):
|
mock.patch('lc_mcp.aalc_engine.time.sleep'):
|
||||||
engine.click(100, 200)
|
engine.click(100, 200)
|
||||||
engine.screen.handle.set_window_transparent.assert_not_called()
|
engine.screen.handle.set_window_transparent.assert_not_called()
|
||||||
|
|
||||||
|
def test_window_cleanup_covers_setup_release_and_restore_failures(self):
|
||||||
|
constants = SimpleNamespace(WM_MOUSEMOVE=512, WM_LBUTTONDOWN=513, WM_LBUTTONUP=514)
|
||||||
|
for action in ('click', 'drag'):
|
||||||
|
for stage in ('move_window', 'activate', 'move_message', 'pre_press_sleep',
|
||||||
|
'release', 'restore'):
|
||||||
|
with self.subTest(action=action, stage=stage):
|
||||||
|
engine = AalcEngine.__new__(AalcEngine)
|
||||||
|
engine.cfg = SimpleNamespace(simulator=False, win_input_type='window_move')
|
||||||
|
engine.auto, engine.screen = mock.Mock(), mock.Mock()
|
||||||
|
engine.auto.input_handler._set_window_pos.return_value = (20, 30)
|
||||||
|
engine._grab = mock.Mock(return_value=SimpleNamespace(width=800, height=600))
|
||||||
|
engine._background_mouse = mock.Mock()
|
||||||
|
engine._restore_background_position = mock.Mock()
|
||||||
|
failure = RuntimeError(stage)
|
||||||
|
if stage == 'move_window':
|
||||||
|
engine.auto.input_handler._set_window_pos.side_effect = failure
|
||||||
|
elif stage == 'activate':
|
||||||
|
engine.auto.input_handler.set_active.side_effect = failure
|
||||||
|
elif stage == 'restore':
|
||||||
|
engine._restore_background_position.side_effect = failure
|
||||||
|
elif stage in ('move_message', 'release'):
|
||||||
|
message = 512 if stage == 'move_message' else 514
|
||||||
|
def send(kind, *args, **kwargs):
|
||||||
|
if kind == message:
|
||||||
|
raise failure
|
||||||
|
engine._background_mouse.side_effect = send
|
||||||
|
with mock.patch.dict(sys.modules, win32con=constants), \
|
||||||
|
mock.patch('lc_mcp.aalc_engine.time.sleep') as sleep:
|
||||||
|
if stage == 'pre_press_sleep':
|
||||||
|
sleep.side_effect = failure
|
||||||
|
with self.assertRaises(RuntimeError):
|
||||||
|
if action == 'click':
|
||||||
|
engine.click(100, 200)
|
||||||
|
else:
|
||||||
|
engine.drag(100, 100, 100, 300)
|
||||||
|
self.assertEqual(engine.screen.handle.set_window_transparent.call_args_list,
|
||||||
|
[mock.call(True), mock.call(False)])
|
||||||
|
if stage != 'move_window':
|
||||||
|
engine._restore_background_position.assert_called_once_with((20, 30))
|
||||||
|
|
||||||
def test_restore_uses_noactivate_and_preserves_foreground(self):
|
def test_restore_uses_noactivate_and_preserves_foreground(self):
|
||||||
gui = mock.Mock()
|
gui = mock.Mock()
|
||||||
gui.GetForegroundWindow.return_value = 123
|
gui.GetForegroundWindow.return_value = 123
|
||||||
|
|||||||
Reference in New Issue
Block a user