def test_event_trigger(self): inp = Input() f = inp.event_trigger(CustomEvent) self.assertEqual(inp.send(0), None) f() self.assertEqual(type(inp.send(0)), CustomEvent) self.assertEqual(inp.send(0), None)
def test_interrupting_sigint(self): inp = Input(sigint_event=True) def send_sigint(): os.kill(os.getpid(), signal.SIGINT) with inp: t = threading.Thread(target=send_sigint) t.start() self.assertEqual(type(inp.send(1)), events.SigIntEvent) self.assertEqual(inp.send(0), None) t.join()
def test_iter(self): inp = Input() inp.send = Mock() inp.send.return_value = None for i, e in zip(range(3), inp): self.assertEqual(e, None) self.assertEqual(inp.send.call_count, 3)
def test_schedule_event_trigger(self): inp = Input() f = inp.scheduled_event_trigger(CustomScheduledEvent) self.assertEqual(inp.send(0), None) f(when=time.time()) self.assertEqual(type(inp.send(0)), CustomScheduledEvent) self.assertEqual(inp.send(0), None) f(when=time.time()+0.01) self.assertEqual(inp.send(0), None) time.sleep(0.01) self.assertEqual(type(inp.send(0)), CustomScheduledEvent) self.assertEqual(inp.send(0), None)
def test_send_paste(self): inp = Input() inp.unprocessed_bytes = [] inp.wait_for_read_ready_or_timeout = Mock() inp.wait_for_read_ready_or_timeout.return_value = (True, None) inp.nonblocking_read = Mock() n = inp.paste_threshold + 1 first_time = [True] def side_effect(): if first_time: inp.unprocessed_bytes.extend([b'a']*n) first_time.pop() return n else: return None inp.nonblocking_read.side_effect = side_effect r = inp.send(0) self.assertEqual(type(r), events.PasteEvent) self.assertEqual(r.events, [u'a'] * n)
def test_send_nonblocking_no_event(self): inp = Input() inp.unprocessed_bytes = [] self.assertEqual(inp.send(0), None)
def test_send(self): inp = Input() inp.unprocessed_bytes = [b'a'] self.assertEqual(inp.send('nonsensical value'), u'a')
def test_send_nonblocking_no_event(self): inp = Input() inp.unprocessed_bytes = [] self.assertEqual(inp.send(0), None)
def test_send(self): inp = Input() inp.unprocessed_bytes = [b'a'] self.assertEqual(inp.send('nonsensical value'), u'a')
def test_send(self): inp = Input() inp.unprocessed_bytes = [b"a"] self.assertEqual(inp.send("nonsensical value"), u"a")