test_exit.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from types import SimpleNamespace
  2. import pytest
  3. from module.base import timer
  4. from tasks.Exploration.base import BaseExploration
  5. class ExitReplay(BaseExploration):
  6. def __init__(self, monkeypatch, frames):
  7. self.frames = iter(frames)
  8. self.frame = set()
  9. self.clicks = []
  10. self.now = 100.0
  11. self.device = SimpleNamespace(click_record_remove=lambda name: None)
  12. monkeypatch.setattr(timer, 'time', SimpleNamespace(time=lambda: self.now))
  13. def screenshot(self):
  14. self.now += 0.5
  15. self.frame = next(self.frames)
  16. def appear(self, asset, **kwargs):
  17. return any(asset is getattr(self, name) for name in self.frame)
  18. def click(self, asset, **kwargs):
  19. self.clicks.append(asset)
  20. return True
  21. def appear_then_click(self, asset, **kwargs):
  22. return self.appear(asset) and self.click(asset, **kwargs)
  23. @pytest.mark.parametrize('second_frame', [
  24. set(), {'I_BACK_YOLLOW'}, {'I_BACK_YOLLOW', 'I_E_EXPLORATION_CLICK'},
  25. ])
  26. def test_exit_does_not_click_back_on_transition_or_unconfirmed_scene(monkeypatch, second_frame):
  27. task = ExitReplay(monkeypatch, [{'I_BACK_YOLLOW'}, second_frame, {'I_CHECK_EXPLORATION'}])
  28. task.quit_explore()
  29. assert task.clicks == []
  30. @pytest.mark.parametrize('marker', ['I_E_SETTINGS_BUTTON', 'I_E_AUTO_ROTATE_ON', 'I_E_AUTO_ROTATE_OFF'])
  31. def test_exit_clicks_back_only_on_verified_exploration_scene(monkeypatch, marker):
  32. task = ExitReplay(monkeypatch, [
  33. {'I_BACK_YOLLOW'}, {'I_BACK_YOLLOW', marker}, {'I_E_EXIT_CONFIRM'}, {'I_CHECK_EXPLORATION'},
  34. ])
  35. task.quit_explore()
  36. assert task.clicks == [task.I_BACK_YOLLOW, task.I_E_EXIT_CONFIRM]
  37. @pytest.mark.parametrize('popup', ['I_E_EXIT_CONFIRM', 'I_BATTLE_REWARD'])
  38. def test_exit_prioritizes_popup_appearing_on_second_screenshot(monkeypatch, popup):
  39. task = ExitReplay(monkeypatch, [
  40. {'I_BACK_YOLLOW'}, {'I_BACK_YOLLOW', 'I_E_SETTINGS_BUTTON', popup},
  41. {popup}, {'I_CHECK_EXPLORATION'},
  42. ])
  43. task.quit_explore()
  44. assert task.clicks == [getattr(task, popup)]