Esempio n. 1
0
    def test_identfy_task_on_loop(self):
        @coroutine
        def other_task():
            return identify_future()

        fut = asyncio.ensure_future(other_task())
        yield from fut
        self.assertNotEqual(fut.result(), identify_future())
Esempio n. 2
0
    def test_identfy_task_on_loop(self):

        @coroutine
        def other_task():
            return identify_future()

        fut = asyncio.ensure_future(other_task())
        yield from fut
        self.assertNotEqual(fut.result(), identify_future())
Esempio n. 3
0
    def test_coroutine_local(self):

        ctx = AsyncLocal()

        @coroutine
        def other_context():
            ctx.test = 45
            return ctx.test

        ctx.test = 40

        fut = asyncio.ensure_future(other_context())
        yield from fut
        self.assertEqual(ctx.test, 40)
        self.assertNotEqual(ctx.test, fut.result())
        self.assertEqual(fut.result(), 45)

        self.assertIn(identify_future(fut), ctx.__storage__)
        ctx.__release_local__(fut)
        self.assertNotIn(identify_future(fut), ctx.__storage__)
Esempio n. 4
0
    def test_coroutine_localstack(self):

        ctx = AsyncLocalStack()

        @coroutine
        def other_context():
            ctx.push(45)
            return ctx.top

        ctx.push(40)

        fut = asyncio.ensure_future(other_context())
        yield from fut
        self.assertEqual(ctx.top, 40)
        self.assertNotEqual(ctx.top, fut.result())
        self.assertEqual(fut.result(), 45)

        self.assertIn(identify_future(fut), ctx._local.__storage__)
        ctx.__release_local__(fut)
        self.assertNotIn(identify_future(fut), ctx._local.__storage__)
Esempio n. 5
0
    def test_coroutine_local(self):

        ctx = AsyncLocal()

        @coroutine
        def other_context():
            ctx.test = 45
            return ctx.test

        ctx.test = 40

        fut = asyncio.ensure_future(other_context())
        yield from fut
        self.assertEqual(ctx.test, 40)
        self.assertNotEqual(ctx.test, fut.result())
        self.assertEqual(fut.result(), 45)

        self.assertIn(identify_future(fut), ctx.__storage__)
        ctx.__release_local__(fut)
        self.assertNotIn(identify_future(fut), ctx.__storage__)
Esempio n. 6
0
    def test_coroutine_localstack(self):

        ctx = AsyncLocalStack()

        @coroutine
        def other_context():
            ctx.push(45)
            return ctx.top

        ctx.push(40)

        fut = asyncio.ensure_future(other_context())
        yield from fut
        self.assertEqual(ctx.top, 40)
        self.assertNotEqual(ctx.top, fut.result())
        self.assertEqual(fut.result(), 45)

        self.assertIn(identify_future(fut), ctx._local.__storage__)
        ctx.__release_local__(fut)
        self.assertNotIn(identify_future(fut), ctx._local.__storage__)
Esempio n. 7
0
    async def test_make_task_with_ctx_factory(self):
        local = AsyncLocal()
        local_man = AsyncLocalManager(locals=[local])
        ctxman = self.CtxManager(local)
        self.callback = False

        async def other_context():
            return local.test

        async_with_context = local_man.make_task_with_ctx_factory(ctx=lambda: ctxman, loop=self.loop)

        fut = async_with_context(other_context())
        await fut

        self.assertFalse(hasattr(local, 'test'))
        self.assertEqual(fut.result(), 45)
        self.assertNotIn(identify_future(fut), local.__storage__)
Esempio n. 8
0
    async def test_make_task_with_ctx_factory(self):
        local = AsyncLocal()
        local_man = AsyncLocalManager(locals=[local])
        ctxman = self.CtxManager(local)
        self.callback = False

        async def other_context():
            return local.test

        async_with_context = local_man.make_task_with_ctx_factory(
            ctx=lambda: ctxman, loop=self.loop)

        fut = async_with_context(other_context())
        await fut

        self.assertFalse(hasattr(local, 'test'))
        self.assertEqual(fut.result(), 45)
        self.assertNotIn(identify_future(fut), local.__storage__)
Esempio n. 9
0
 def other_task():
     return identify_future()
Esempio n. 10
0
 def test_identfy_future(self):
     fut = Future()
     self.assertEqual(id(fut), identify_future(fut))
Esempio n. 11
0
 def test_identfy_current_task(self):
     self.assertEqual(id(Task.current_task()), identify_future())
Esempio n. 12
0
 def other_task():
     return identify_future()
Esempio n. 13
0
 def test_identfy_future(self):
     fut = Future()
     self.assertEqual(id(fut), identify_future(fut))
Esempio n. 14
0
 def test_identfy_current_task(self):
     self.assertEqual(id(Task.current_task()), identify_future())