def test_blowup(self): cell = IOCell() @asyncio.coroutine def f(route): raise RuntimeError() cell.add_tier(f) self.assertRaises(RuntimeError, list, cell)
def test_yield_from(self): cell = IOCell() @asyncio.coroutine def coro(route): yield from route.emit((yield from self.add(2, 3))) cell.add_tier(coro) self.assertEqual(list(cell), [5])
def test_multi_emitter_1level(self): cell = IOCell() @asyncio.coroutine def f(route): yield from route.emit(123) yield from route.emit(321) cell.add_tier(f) self.assertEqual(list(cell), [123, 321])
def test_varargs(self): cell = IOCell() @asyncio.coroutine def f(route): yield from route.emit(*'abc') yield from route.emit(*'def') cell.add_tier(f) self.assertEqual(list(cell), list('abcdef'))
def test_one_tier_no_emit(self): cell = IOCell() refcnt = 0 @asyncio.coroutine def f(route): nonlocal refcnt refcnt += 1 cell.add_tier(f) self.assertFalse(list(cell)) self.assertEqual(refcnt, 1)
def test_cascaded_tiers(self): cell = IOCell() @asyncio.coroutine def f(route): yield from route.emit(123) @asyncio.coroutine def f2(route, foo): self.assertEqual(foo, 123) t1 = cell.add_tier(f) cell.add_tier(f2, source=[t1]) self.assertFalse(list(cell))
def test_single_final(self): cell = IOCell() refcnt = 0 @asyncio.coroutine def f(route): nonlocal refcnt refcnt += 1 yield from route.emit(123) cell.add_tier(f) results = list(cell) self.assertEqual(refcnt, 1) self.assertEqual(results, [123])
def test_varargs(self): cell = IOCell() @asyncio.coroutine def f(route): yield from route.emit(123, 345) @asyncio.coroutine def f2(route, foo, bar): self.assertEqual(foo, 123) self.assertEqual(bar, 345) t1 = cell.add_tier(f) cell.add_tier(f2, source=[t1]) self.assertFalse(list(cell))
def test_multi_blowup(self): cell = IOCell() @asyncio.coroutine def f(route): raise RuntimeError() cell.add_tier(f) @asyncio.coroutine def f2(route): raise ValueError() cell.add_tier(f2) it = iter(cell) self.assertRaises(RuntimeError, next, it) self.assertRaises(StopIteration, next, it) # ValueError is dropped.
def test_multi_emitter_2level(self): cell = IOCell() @asyncio.coroutine def f(route): yield from route.emit(123) yield from route.emit(321) t = cell.add_tier(f) @asyncio.coroutine def f2(route, number): yield from route.emit(-number) yield from route.emit(number + 1) cell.add_tier(f2, source=t) self.assertEqual(list(cell), [-123, 124, -321, 322])
def test_cascaded_tiers_no_emit(self): cell = IOCell() refcnt = 0 @asyncio.coroutine def f(route): nonlocal refcnt refcnt += 1 @asyncio.coroutine def f2(route): nonlocal refcnt refcnt += 1 t1 = cell.add_tier(f) cell.add_tier(f2, source=t1) self.assertFalse(list(cell)) self.assertEqual(refcnt, 1)
def test_multi_emitter_multi_source(self): cell = IOCell() @asyncio.coroutine def a1(route): yield from route.emit('a1-1') yield from route.emit('a1-2') a1t = cell.add_tier(a1) @asyncio.coroutine def a2(route): yield from route.emit('a2-1') yield from route.emit('a2-2') a2t = cell.add_tier(a2) @asyncio.coroutine def b(route, value): yield from route.emit(value) cell.add_tier(b, source=[a1t, a2t]) self.assertEqual(list(cell), ['a1-1', 'a2-1', 'a1-2', 'a2-2'])