1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
from asciimatics.effects import Effect
from asciimatics.exceptions import StopApplication, NextScene
class MockEffect(Effect):
"""
Dummy Effect use for some UTs.
"""
def __init__(self, count=10, stop=True, swallow=False, next_scene=None,
frame_rate=1, stop_frame=5, **kwargs):
"""
:param count: When to stop effect
:param stop: Whether to stop the application or skip to next scene.
:param swallow: Whether to swallow any events or not.
:param next_scene: The next scene to move to (if stop=False)
:param frame_rate: The frame rate for updates.
"""
super().__init__(None, **kwargs)
self.stop_called = False
self.reset_called = False
self.event_called = False
self.save_called = False
self.update_called = False
self._count = count
self._stop = stop
self._swallow = swallow
self._next_scene = next_scene
self._frame_rate = frame_rate
# Ugly hack to stop clash with underlying Effect definition. Sorry.
self._my_stop_frame = stop_frame
@property
def stop_frame(self):
self.stop_called = True
return self._my_stop_frame
@property
def frame_update_count(self):
return self._frame_rate
def _update(self, frame_no):
self.update_called = True
self._count -= 1
if self._count <= 0:
if self._stop:
raise StopApplication("End of test")
else:
raise NextScene(self._next_scene)
def reset(self):
self.reset_called = True
def process_event(self, event):
self.event_called = True
return None if self._swallow else event
def save(self):
self.save_called = True
|