test_dokan_create.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from types import SimpleNamespace
  2. import pytest
  3. from module.exception import TaskEnd
  4. from tasks.Dokan.script_task import ScriptTask, DokanScene
  5. @pytest.mark.parametrize('already_inside,enabled,count,creates', [
  6. (True, True, 2, 1), (False, True, 2, 1),
  7. (True, False, 2, 0), (True, True, 0, 0),
  8. ])
  9. def test_create_once_per_entry_and_not_each_search_loop(already_inside, enabled, count, creates):
  10. task = object.__new__(ScriptTask)
  11. task.config = SimpleNamespace(save=lambda: None, dokan=SimpleNamespace(
  12. dokan_config=SimpleNamespace(dokan_attack_priority=0, monday_to_thursday=False,
  13. try_start_dokan=enabled, find_dokan_score=2),
  14. attack_count_config=SimpleNamespace(init_attack_count=lambda **kwargs: None),
  15. ))
  16. events = []
  17. reads = 0
  18. def scene(*args):
  19. nonlocal reads
  20. reads += 1
  21. assert reads < 10
  22. return (already_inside or reads > 1, DokanScene.RYOU_DOKAN_SCENE_FINDING_DOKAN)
  23. task.get_current_scene = scene
  24. task.goto_dokan_scene = lambda: events.append('enter')
  25. task.update_remain_attack_count = lambda: count
  26. task.creat_dokan = lambda: events.append('create')
  27. results = iter([True, False])
  28. task.find_dokan = lambda score: next(results)
  29. task.screenshot = lambda: None
  30. task.wait_until_appear = lambda *args: None
  31. task.goto_main = lambda: None
  32. task.next_run = lambda **kwargs: None
  33. with pytest.raises(TaskEnd):
  34. task.run()
  35. assert events.count('create') == creates
  36. assert events.count('enter') == int(not already_inside)