Ejemplo n.º 1
0
    def test_ctx_var_reset(self):
        # fmt: off
        async_eval(
            textwrap.dedent("""
        from asyncio import sleep
        token = ctx_var.set(10)
        await sleep(0)  # switch to different task
        ctx_var.reset(token)
        """))
        # fmt: on

        assert ctx_var.get() == 0
Ejemplo n.º 2
0
 def test_ctx_set(self):
     async_eval("ctx_var.set(10)")
     assert ctx_var.get() == 10
Ejemplo n.º 3
0
 def test_ctx_get(self):
     assert async_eval("ctx_var.get()") == 0
Ejemplo n.º 4
0
async def test_async_eval_dont_leak_internal_vars():
    _globals = _locals = {}
    async_eval("10", _globals, _locals)

    assert not _globals
    assert not _locals
Ejemplo n.º 5
0
async def test_eval_raise_exc():
    with raises(MyException):
        async_eval("await raise_exc()")
Ejemplo n.º 6
0
async def test_async_eval_modify_locals(expr, result):
    a = None
    async_eval(expr)
    assert a == result
Ejemplo n.º 7
0
async def test_async_eval(expr, result):
    assert async_eval(expr) == result