test_friend_tab.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from types import SimpleNamespace
  2. import numpy as np
  3. import pytest
  4. from module.atom import image
  5. from tasks.Component.GeneralInvite.general_invite import GeneralInvite
  6. @pytest.mark.parametrize('padding', [0, 2])
  7. def test_first_friend_tab_ignores_surrounding_colors(monkeypatch, padding):
  8. task = object.__new__(GeneralInvite)
  9. task.device = SimpleNamespace(image=np.zeros((720, 1280, 3), dtype=np.uint8))
  10. x, y, w, h = task.I_FLAG_1_ON.roi_back
  11. badge = task.device.image[y:y+h, x:x+w]
  12. badge[:] = (156, 110, 86)
  13. clicks = []
  14. frames = 0
  15. def screenshot():
  16. nonlocal frames
  17. frames += 1
  18. assert frames < 9
  19. def click(rule, interval):
  20. assert rule is task.I_FLAG_1_OFF
  21. clicks.append(rule)
  22. badge[:] = (227, 193, 153)
  23. return True
  24. task.screenshot = screenshot
  25. task.click = click
  26. task.appear = lambda rule: rule is task.I_LOAD_FRIEND
  27. task.detect_select = lambda name: True
  28. for i in range(1, 5):
  29. label = '好友' if i == 1 else ''
  30. setattr(task, f'O_F_LIST_{i}', SimpleNamespace(ocr=lambda frame, label=label: label))
  31. monkeypatch.setattr(image, 'ROI_MATCH_PAD', padding)
  32. monkeypatch.setattr('tasks.Component.GeneralInvite.general_invite.sleep', lambda _: None)
  33. assert task.invite_friend('friend')
  34. assert clicks == [task.I_FLAG_1_OFF]