- install_safe_blank_click: auto.mouse_click_blank 改成只调 mouse_to_blank, mouse_to_blank 改成 移到客户区 (12,12) 换算出的屏幕点; LCP_BLANK_CLICK=1 还原 - 必须在 driver_click_tasks 之后再装一次: 驱动代理会把 auto.mouse_click_blank 重绑回代理, 第一次装在被覆盖, 20 分钟里仍有 391 次 点击客户区(1,1) - tests: test_safe_blank_click 4 例 单测: 783 passed。
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""「点空白」不再点到桌面回收站。
|
|
|
|
2026-11-22: 一轮 20 分钟里 391 次 `点击客户区(1,1)` + 87 次 `鼠标移动到空白`, 全是
|
|
mouse_click_blank()/mouse_to_blank() 的默认坐标 (1,1)。窗口一偏移这点就落到桌面左上角
|
|
回收站图标上。
|
|
"""
|
|
import sys
|
|
import types
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(REPO))
|
|
from lc_mcp import aalc_patches as ap # noqa: E402
|
|
from lc_mcp import driver_input as di # noqa: E402
|
|
|
|
|
|
class SafeBlankClickTest(unittest.TestCase):
|
|
|
|
def install(self, auto, env=None):
|
|
module = types.ModuleType('module.automation')
|
|
module.auto = auto
|
|
with mock.patch.dict(sys.modules, {'module': types.ModuleType('module'),
|
|
'module.automation': module}):
|
|
return ap.install_safe_blank_click(log=lambda *_: None, env=env or {})
|
|
|
|
def make_auto(self):
|
|
auto = mock.Mock()
|
|
auto.screen.handle.hwnd = 99
|
|
auto.mouse_click_blank.return_value = True
|
|
auto.mouse_to_blank.return_value = None
|
|
return auto
|
|
|
|
def test_click_blank_only_moves_cursor(self):
|
|
auto = self.make_auto()
|
|
self.install(auto)
|
|
with mock.patch.object(di, 'client_to_screen', return_value=(25, 50)) as c2s:
|
|
self.assertTrue(auto.mouse_click_blank())
|
|
c2s.assert_called_once_with(99, *ap.BLANK_SAFE_CLIENT)
|
|
|
|
def test_move_blank_uses_client_safe_point(self):
|
|
auto = self.make_auto()
|
|
original_move = auto.mouse_to_blank
|
|
self.install(auto)
|
|
with mock.patch.object(di, 'client_to_screen', return_value=(25, 50)):
|
|
auto.mouse_to_blank()
|
|
# 传给原方法的是屏幕坐标 (25,50), 不是 (1,1)
|
|
original_move.assert_called_once_with((25, 50), move_back=False)
|
|
|
|
def test_env_one_keeps_upstream(self):
|
|
auto = self.make_auto()
|
|
self.assertIsNone(self.install(auto, env={ap.BLANK_CLICK_ENV: '1'}))
|
|
|
|
def test_missing_auto_methods_skips(self):
|
|
auto = mock.Mock(spec=[])
|
|
self.assertIsNone(self.install(auto))
|