test_battle_navigation.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from datetime import datetime
  2. import pytest
  3. from tasks.OtherWorldTwilight import script_task as owt_module
  4. from tasks.OtherWorldTwilight.config import OtherWorldTwilight
  5. from tasks.GameUi.page import page_battle, page_battle_prepare, page_battle_result, page_reward
  6. from tasks.OtherWorldTwilight.page import page_owt
  7. class SoloReplay(owt_module.ScriptTask):
  8. def __init__(self, page):
  9. self.conf = OtherWorldTwilight()
  10. self.conf.other_world_twilight_config.limit_count = 1
  11. self.current_count = 0
  12. self.start_time = datetime.now()
  13. self.page = page
  14. self.frames = 0
  15. self.destinations = []
  16. self.battles = []
  17. def goto_page(self, page):
  18. self.destinations.append(page)
  19. if len(self.destinations) > 1:
  20. self.current_count = 1
  21. def check_lock(self, *args):
  22. pass
  23. def screenshot(self):
  24. self.frames += 1
  25. assert self.frames < 5, 'unrecognized page never triggered recovery'
  26. def get_current_page(self, *args):
  27. return self.page
  28. def run_general_battle(self, config):
  29. self.battles.append(config)
  30. self.current_count += 1
  31. return True
  32. @pytest.mark.parametrize('page', [page_battle_prepare, page_battle, page_reward, page_battle_result])
  33. def test_solo_takes_over_all_battle_pages_and_counts_settlement(page):
  34. task = SoloReplay(page.clone())
  35. task.run_alone()
  36. assert task.battles == [task.conf.general_battle_config]
  37. assert task.current_count == 1
  38. assert task.destinations == [page_owt]
  39. def test_solo_recovers_when_no_page_can_be_recognized(monkeypatch):
  40. class ExpiredAfterStart:
  41. active = False
  42. def __init__(self, limit):
  43. assert limit == 10
  44. def started(self):
  45. return self.active
  46. def start(self):
  47. self.active = True
  48. def reached(self):
  49. return self.active
  50. def clear(self):
  51. self.active = False
  52. monkeypatch.setattr(owt_module, 'Timer', ExpiredAfterStart)
  53. monkeypatch.setattr(owt_module, 'sleep', lambda seconds: None)
  54. task = SoloReplay(None)
  55. task.run_alone()
  56. assert task.destinations == [page_owt, page_owt]
  57. assert task.battles == []