Ejemplo n.º 1
0
    async def sub():
        old = Scope.get_current()
        assert old == n

        async with old.fork() as new:
            assert Scope.get_current() == new

            async def test_old():
                assert Scope.get_current() == old

            async def test_new():
                assert Scope.get_current() == new

            await test_new()
            await asyncio.ensure_future(test_new())
            new << test_new()

            old << test_old()
Ejemplo n.º 2
0
async def test_context():
    """
    Check Scope.get_current() in different situations
    """
    assert Scope.get_current() is None

    # Create a first Scope
    n = Scope()

    n2 = Scope()

    Scope._set_current(n2)
    assert Scope.get_current() == n2

    async def sub():
        old = Scope.get_current()
        assert old == n

        async with old.fork() as new:
            assert Scope.get_current() == new

            async def test_old():
                assert Scope.get_current() == old

            async def test_new():
                assert Scope.get_current() == new

            await test_new()
            await asyncio.ensure_future(test_new())
            new << test_new()

            old << test_old()

    async with n:
        assert Scope.get_current() == n

        n << sub()

    assert Scope.get_current() == n2

    Scope._set_current(None)
    assert Scope.get_current() is None
Ejemplo n.º 3
0
 async def cleaner():
     await asyncio.sleep(0.2)
     Scope.get_current().cancel(ValueError('boom'))
     # Should we raise something in case of double close?
     Scope.get_current().cancel(ValueError('boom'))
Ejemplo n.º 4
0
 async def cleaner():
     await asyncio.sleep(0.2)
     Scope.get_current().cancel()
     await asyncio.sleep(10)
Ejemplo n.º 5
0
 async def test_new():
     assert Scope.get_current() == new
Ejemplo n.º 6
0
 async def test_old():
     assert Scope.get_current() == old