def setUp(self): be.yield_() def doyield(): be.yield_() self.addCleanup(doyield)
def test_exc(self): def raiseit(): raise RuntimeError('ha!') goless.go(raiseit) be.yield_() self.assertEqual(len(self.panic_calls), 1)
def test_exc(self): def raiseit(): raise RuntimeError("ha!") goless.go(raiseit) be.yield_() self.assertEqual(len(self.panic_calls), 1)
def test_be_has_correct_sender_receiver_priority(self): c = be.channel() r = [] def do_send(): r.append("s1") c.send(None) r.append("s2") def do_receive(): r.append("r1") c.receive() r.append("r2") be.run(do_receive) be.run(do_send) be.yield_() self.assertEqual(["r1", "s1", "r2", "s2"], r)
def _test_channel_raises_when_closed(self, chan_method_name): chan = self.makechan() method = getattr(chan, chan_method_name) marker = [] def catch_raise(): try: method() except gochans.ChannelClosed: marker.append(1) marker.append(2) be.run(catch_raise) chan.close() be.yield_() self.assertEqual(marker, [1, 2])
def test_select_no_default_no_ready_blocks(self): chan1 = goless.chan() chan2 = goless.chan() a = [] cases = [goless.rcase(chan2), goless.rcase(chan1)] def sel(): a.append(goless.select(cases)) be.run(sel) self.assertEqual(a, []) chan1.send(5) be.yield_() self.assertEqual(len(a), 1) chosen, val = a[0] self.assertEqual(chosen, cases[1]) self.assertEqual(val, 5)
def test_starts_stuff(self): items = [] goless.go(lambda: items.append(1)) be.yield_() self.assertEqual(items, [1])
def tearDown(self): be.yield_() self.assertTrue(be.would_deadlock(), 'Task(s) still running after test finished')
def setUp(self): be.yield_()
def doyield(): be.yield_()
def test_starts_with_params(self): called = mock.Mock() goless.go(called, 10, a=1) be.yield_() called.assert_called_once_with(10, a=1)