| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- from types import SimpleNamespace
- import numpy as np
- import pytest
- from module.atom import image
- from tasks.Component.GeneralInvite.general_invite import GeneralInvite
- @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]
|