30 lines
1.7 KiB
Python
30 lines
1.7 KiB
Python
import json, sys
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
import cv2, numpy as np
|
|
from wechat_bot import WeChatBot
|
|
sys.stdout.reconfigure(encoding="utf-8")
|
|
image_path=Path(sys.argv[1])
|
|
image=cv2.imdecode(np.frombuffer(image_path.read_bytes(), dtype=np.uint8), cv2.IMREAD_COLOR)
|
|
bot=WeChatBot.__new__(WeChatBot)
|
|
bot.scale=2.0
|
|
width=bot._nav_column_width_px(image,bot.scale)
|
|
band=bot._message_nav_band(image)
|
|
selected=bot._message_nav_selected(image)
|
|
print("Screenshot navigation:", width, "message band:", band, "selected:", selected, flush=True)
|
|
assert width==116 and band[2] and 240 <= (band[0]+band[1])//2 <= 336 and selected
|
|
bot.hwnd=100
|
|
bot.wait_for_mouse_idle=mock.Mock(return_value=True)
|
|
bot._security_gate_visible=mock.Mock(return_value=False)
|
|
bot._begin_bot_mouse=mock.Mock(); bot._end_bot_mouse=mock.Mock()
|
|
bot._capture_full_window=mock.Mock(return_value=image)
|
|
bot._refresh_message_geometry=mock.Mock()
|
|
with mock.patch("wechat_bot.safe_set_foreground",return_value=True), mock.patch("wechat_bot.win32gui.GetForegroundWindow",return_value=100), mock.patch("wechat_bot.win32gui.GetWindowRect",return_value=(0,0,614,1476)), mock.patch("wechat_bot.pyautogui.click") as click, mock.patch("wechat_bot.time.sleep"):
|
|
assert bot._open_messages_page("截图回归:")
|
|
click.assert_called_once()
|
|
x,y=click.call_args.args
|
|
assert 0<x<116 and 240<y<336
|
|
print("Verified simulated click:",(x,y),"No real mouse action performed.",flush=True)
|
|
result={"image_size":[614,1476],"navigation_width":width,"message_band":band,"selected":selected,"simulated_click":[x,y],"real_clicks":0,"real_messages_sent":0}
|
|
Path("tmp/message-nav-screenshot-verification.json").write_text(json.dumps(result,indent=2),encoding="utf-8")
|