Ejemplo n.º 1
0
 def test_blowup(self):
     cell = IOCell()
     @asyncio.coroutine
     def f(route):
         raise RuntimeError()
     cell.add_tier(f)
     self.assertRaises(RuntimeError, list, cell)
Ejemplo n.º 2
0
 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])
Ejemplo n.º 3
0
 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])
Ejemplo n.º 4
0
 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'))
Ejemplo n.º 5
0
    def test_blowup(self):
        cell = IOCell()

        @asyncio.coroutine
        def f(route):
            raise RuntimeError()

        cell.add_tier(f)
        self.assertRaises(RuntimeError, list, cell)
Ejemplo n.º 6
0
    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])
Ejemplo n.º 7
0
    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'))
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
    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])
Ejemplo n.º 10
0
 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))
Ejemplo n.º 11
0
 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])
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
 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))
Ejemplo n.º 14
0
 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.
Ejemplo n.º 15
0
 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])
Ejemplo n.º 16
0
    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))
Ejemplo n.º 17
0
    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])
Ejemplo n.º 18
0
 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)
Ejemplo n.º 19
0
    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))
Ejemplo n.º 20
0
 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'])
Ejemplo n.º 21
0
    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.
Ejemplo n.º 22
0
    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])
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
    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'])