def test_parked_closed(self): ch = Channel() def closing(): yield sleep(0.005) ch.close() go(closing) self.assertEqual((yield put(ch, 42)), False)
def test_immediate_puts_and_takes(self): ch = Channel(1) i = 0 while i < self.limit: i += 1 yield put(ch, 1) yield take(ch)
def test_parked_taken(self): ch = Channel() def taking(): yield sleep(0.005) yield take(ch) go(taking) self.assertEqual((yield put(ch, 42)), True)
def test_no_priority(self): nums = range(50) chs = [Channel(1) for _ in nums] for i in nums: yield put(chs[i], i) values = [] for _ in nums: values.append((yield alts(chs)).value) self.assertNotEqual(values, nums)
def test_default_value(self): ch = Channel(1) r = yield alts([ch], default=42) self.assertEqual(r.value, 42) self.assertEqual(r.channel, DEFAULT) yield put(ch, 53) r = yield alts([ch], default=42) self.assertEqual(r.value, 53) self.assertEqual(r.channel, ch)
def test_immediate_buffered(self): ch = Channel(1) yield put(ch, 42) self.assertEqual((yield take(ch)), 42)
def putting(): yield put(ch, 42)
def test_immediate_closed(self): ch = Channel() ch.close() self.assertEqual((yield put(ch, 42)), False)
def test_immediate_buffered(self): ch = Channel(1) self.assertEqual((yield put(ch, 42)), True)
def test_putting_onto_closed_channel(self): i = 0 while i < self.limit: i += 1 yield put(self.ch, 42)
def test_immediate_taken(self): ch = Channel() def taking(): yield take(ch) go(taking) self.assertEqual((yield put(ch, 42)), True)
def putting(): yield sleep(0.005) yield put(ch, 42)