| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- from types import SimpleNamespace
- import numpy as np
- import pytest
- from module.atom import image
- from tasks.Component.GeneralInvite.config_invite import FindMode
- from tasks.Component.GeneralInvite.general_invite import GeneralInvite, RoomType
- @pytest.mark.parametrize('padding', [0, 2])
- def test_first_friend_tab_ignores_surrounding_colors(monkeypatch, padding):
- task = object.__new__(GeneralInvite)
- task.device = SimpleNamespace(image=np.zeros((720, 1280, 3), dtype=np.uint8))
- x, y, w, h = task.I_FLAG_1_ON.roi_back
- badge = task.device.image[y:y+h, x:x+w]
- badge[:] = (156, 110, 86)
- clicks = []
- frames = 0
- def screenshot():
- nonlocal frames
- frames += 1
- assert frames < 9
- def click(rule, interval):
- assert rule is task.I_FLAG_1_OFF
- clicks.append(rule)
- badge[:] = (227, 193, 153)
- return True
- task.screenshot = screenshot
- task.click = click
- task.appear = lambda rule: rule is task.I_LOAD_FRIEND
- task.detect_select = lambda name: True
- for i in range(1, 5):
- label = '好友' if i == 1 else ''
- setattr(task, f'O_F_LIST_{i}', SimpleNamespace(ocr=lambda frame, label=label: label))
- monkeypatch.setattr(image, 'ROI_MATCH_PAD', padding)
- monkeypatch.setattr('tasks.Component.GeneralInvite.general_invite.sleep', lambda _: None)
- assert task.invite_friend('friend')
- assert clicks == [task.I_FLAG_1_OFF]
- @pytest.mark.parametrize('mode', [FindMode.AUTO_FIND, FindMode.RECENT_FRIEND])
- def test_second_tab_uses_selected_template_inside_wider_search_area(monkeypatch, mode):
- task = object.__new__(GeneralInvite)
- frame = np.zeros((720, 1280, 3), dtype=np.uint8)
- task.device = SimpleNamespace(image=frame)
- for index, label in enumerate(('好友', '最近', '', ''), start=1):
- setattr(task, f'O_F_LIST_{index}', SimpleNamespace(ocr=lambda _, label=label: label))
- def show_selected(rule):
- x, y, w, h = rule.roi_front
- frame[y:y+h, x:x+w] = rule.image
- show_selected(task.I_FLAG_1_ON)
- clicks = []
- def click(rule, interval):
- assert rule is task.I_FLAG_2_OFF and not clicks
- clicks.append(rule)
- show_selected(task.I_FLAG_2_ON)
- return True
- task.appear = lambda rule: rule is task.I_LOAD_FRIEND
- task.appear_then_click = click
- task.screenshot = lambda: None
- task.detect_select = lambda name: bool(clicks)
- monkeypatch.setattr('tasks.Component.GeneralInvite.general_invite.sleep', lambda _: None)
- assert task.invite_friend('friend', mode)
- assert clicks == [task.I_FLAG_2_OFF]
- def test_full_three_player_room_finishes_before_opening_another_invitation():
- task = object.__new__(GeneralInvite)
- task.room_type = RoomType.NORMAL_3
- task.appear = lambda rule: rule is task.I_GI_EMOJI_1
- frames = iter([None])
- task.screenshot = lambda: next(frames)
- task.appear_then_click = lambda rule, interval: False
- assert task.invite_friend('friend')
|