test_world_transition.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. """Replay post-battle transitions without a device or a 60-second watchdog wait."""
  2. from types import SimpleNamespace
  3. from unittest.mock import Mock
  4. import pytest
  5. from tasks.Exploration.base import Scene
  6. from tasks.Exploration.solo import SoloExploration
  7. class SceneReplay(SoloExploration):
  8. def __init__(self, *frames):
  9. self.frames = iter(frames)
  10. self.frame = set()
  11. self.clicks = []
  12. self.device = SimpleNamespace(click_record_remove=Mock())
  13. self.interval_timer = {}
  14. def screenshot(self):
  15. frame = next(self.frames, None)
  16. assert frame is not None, 'Exploration kept waiting after the last replay frame'
  17. self.frame = set(frame)
  18. def appear(self, asset, **kwargs):
  19. return any(asset is getattr(self, name) for name in self.frame)
  20. def appear_then_click(self, asset, **kwargs):
  21. if self.appear(asset):
  22. self.clicks.append(asset)
  23. return True
  24. return False
  25. @pytest.mark.parametrize('marker,scene', [
  26. ('I_E_EXPLORATION_CLICK', Scene.ENTRANCE),
  27. ('I_E_AUTO_ROTATE_ON', Scene.MAIN),
  28. ('I_E_AUTO_ROTATE_OFF', Scene.MAIN),
  29. ])
  30. def test_chapter_controls_take_precedence_over_world_marker(marker, scene):
  31. task = SceneReplay(('I_CHECK_EXPLORATION', marker))
  32. assert task.get_current_scene(reuse_screenshot=False) == scene
  33. @pytest.mark.parametrize('frame', [
  34. ('I_E_SETTINGS_BUTTON', 'I_EXP_ARROW_LEFT'), ('I_E_EXPLORATION_CLICK', 'I_EXP_ARROW_LEFT'),
  35. ('I_PREPARE_HIGHLIGHT', 'I_EXP_ARROW_LEFT'), ('I_BATTLE_INFO', 'I_EXP_ARROW_LEFT'),
  36. ('I_GI_EMOJI_1', 'I_EXP_ARROW_LEFT'), ('I_CHECK_EXPLORATION',), (),
  37. ])
  38. def test_world_check_yields_unready_frames_without_clicking(frame):
  39. task = SceneReplay(frame)
  40. assert task.wait_world_stable() is False
  41. assert task.clicks == []
  42. def test_hidden_world_panel_can_be_opened_when_its_marker_is_not_visible():
  43. task = SceneReplay(('I_EXP_ARROW_LEFT',), ('I_EXP_ARROW_LEFT',),
  44. ('I_CHECK_EXPLORATION', 'I_EXP_ARROW_RIGHT'))
  45. assert task.get_current_scene(reuse_screenshot=False) == Scene.WORLD
  46. assert task.wait_world_stable() is False
  47. assert task.clicks == [task.I_EXP_ARROW_LEFT]
  48. assert task.wait_world_stable() is True
  49. assert task.clicks == [task.I_EXP_ARROW_LEFT]
  50. @pytest.mark.parametrize('mode', ['run_solo', 'run_leader'])
  51. def test_transient_world_after_battle_keeps_chapter_search_state(mode):
  52. task = SceneReplay(('I_CHECK_EXPLORATION',), ('I_E_SETTINGS_BUTTON',),
  53. ('I_E_SETTINGS_BUTTON',),
  54. ('I_CHECK_EXPLORATION',), ('I_CHECK_EXPLORATION', 'I_EXP_ARROW_RIGHT'))
  55. task.explore_init = True
  56. task.swipe_cnt = 2
  57. continued = []
  58. def handle_chapter():
  59. continued.append((task.explore_init, task.swipe_cnt))
  60. return True
  61. task._handle_treasure_box = handle_chapter
  62. task.check_exit = Mock(return_value=True)
  63. task.wait_until_stable = Mock() # The leader also checks for a pending invite on exit.
  64. getattr(task, mode)()
  65. assert continued == [(True, 2)]
  66. task.device.click_record_remove.assert_called_once_with(task.S_SWIPE_BACKGROUND_RIGHT.name)
  67. task.check_exit.assert_called_once_with()
  68. assert not task.explore_init and task.swipe_cnt == 0