| 11 | |
| 12 | |
| 13 | class EventGenerator: |
| 14 | def __init__(self, initial_events=(), scheduled_events=()): |
| 15 | self._events = [] |
| 16 | self._current_tick = 0 |
| 17 | for e in initial_events: |
| 18 | self.schedule_event(e, 0) |
| 19 | for e, w in scheduled_events: |
| 20 | self.schedule_event(e, w) |
| 21 | |
| 22 | def schedule_event(self, event, when): |
| 23 | self._events.append(ScheduledEvent(when, event)) |
| 24 | self._events.sort() |
| 25 | |
| 26 | def send(self, timeout=None): |
| 27 | if timeout not in [None, 0]: |
| 28 | raise ValueError("timeout value %r not supported" % timeout) |
| 29 | if not self._events: |
| 30 | return None |
| 31 | if self._events[0].when <= self._current_tick: |
| 32 | return self._events.pop(0).event |
| 33 | |
| 34 | if timeout == 0: |
| 35 | return None |
| 36 | elif timeout is None: |
| 37 | e = self._events.pop(0) |
| 38 | self._current_tick = e.when |
| 39 | return e.event |
| 40 | else: |
| 41 | raise ValueError("timeout value %r not supported" % timeout) |
| 42 | |
| 43 | def tick(self, dt=1): |
| 44 | self._current_tick += dt |
| 45 | return self._current_tick |
| 46 | |
| 47 | |
| 48 | class TestCurtsiesPasteDetection(TestCase): |
no outgoing calls