test_contribution.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import pytest
  2. from tasks.MemoryScrolls.script_task import ScriptTask
  3. class ContributionReplay(ScriptTask):
  4. def __init__(self, *, empty=False, stuck=False, popup=False):
  5. self.empty = empty
  6. self.stuck = stuck
  7. self.popup = popup
  8. self.frames = 0
  9. self.clicks = []
  10. self.contributions = 0
  11. def screenshot(self):
  12. self.frames += 1
  13. assert self.frames <= 120, 'Contribution did not stop on a stuck screen'
  14. def appear(self, asset, **kwargs):
  15. return self.empty and asset in (self.I_MS_ZERO_S, self.I_MS_ZERO_M, self.I_MS_ZERO_L)
  16. def appear_then_click(self, asset, **kwargs):
  17. assert asset is self.I_MS_CONTRIBUTE
  18. self.contributions += 1
  19. self.empty = not self.stuck
  20. return True
  21. def wait_until_appear(self, asset, **kwargs):
  22. assert asset is self.I_MS_CONTRIBUTED
  23. return self.popup
  24. def click(self, asset, **kwargs):
  25. self.clicks.append(asset.name)
  26. return True
  27. def swipe(self, *args, **kwargs):
  28. pytest.fail('Contribution must use the maximum buttons on the new UI')
  29. @pytest.fixture(autouse=True)
  30. def skip_animation_delays(monkeypatch):
  31. monkeypatch.setattr('tasks.MemoryScrolls.script_task.sleep', lambda _: None)
  32. def test_empty_inventory_does_not_contribute():
  33. task = ContributionReplay(empty=True)
  34. task.contribute_memoryscrolls()
  35. assert task.contributions == 0
  36. assert task.clicks == []
  37. def test_contribution_selects_all_sizes_and_stops_when_empty():
  38. task = ContributionReplay()
  39. task.contribute_memoryscrolls()
  40. assert task.contributions == 1
  41. assert task.clicks == [
  42. task.C_MS_MAX_S.name, task.C_MS_MAX_S.name,
  43. task.C_MS_MAX_M.name, task.C_MS_MAX_M.name,
  44. task.C_MS_MAX_L.name, task.C_MS_MAX_L.name,
  45. ]
  46. @pytest.mark.parametrize('popup', [False, True])
  47. def test_stuck_inventory_and_reward_popup_are_bounded(popup):
  48. task = ContributionReplay(stuck=True, popup=popup)
  49. task.contribute_memoryscrolls()
  50. assert task.contributions == 10
  51. assert task.clicks.count(task.C_MS_CONTRIBUTED.name) == (100 if popup else 0)