MCPcopy Index your code
hub / github.com/bpython/bpython / EventGenerator

Class EventGenerator

bpython/test/test_curtsies.py:13–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class 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
48class TestCurtsiesPasteDetection(TestCase):

Callers 2

test_paste_thresholdMethod · 0.85
test_set_timeoutMethod · 0.85

Calls

no outgoing calls

Tested by 2

test_paste_thresholdMethod · 0.68
test_set_timeoutMethod · 0.68