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