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 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
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'))
async def cleaner(): await asyncio.sleep(0.2) Scope.get_current().cancel() await asyncio.sleep(10)
async def test_new(): assert Scope.get_current() == new
async def test_old(): assert Scope.get_current() == old