Exemplo n.º 1
0
def test_install_ast_funcs(ast_functions):  # pylint: disable=redefined-outer-name
    """Test installing ast functions."""
    ast_ctx = MagicMock()
    ast_ctx.func.return_value = "ok"

    with patch.object(Function, "ast_functions", ast_functions):
        Function.install_ast_funcs(ast_ctx)
        assert len(ast_ctx.method_calls) == 3
Exemplo n.º 2
0
async def run_one_test(test_data):
    """Run one interpreter test."""
    source, expect = test_data
    global_ctx = GlobalContext("test", global_sym_table={}, manager=GlobalContextMgr)
    ast = AstEval("test", global_ctx=global_ctx)
    Function.install_ast_funcs(ast)
    ast.parse(source)
    if ast.get_exception() is not None:
        print(f"Parsing {source} failed: {ast.get_exception()}")
    # print(ast.dump())
    result = await ast.eval({"sym_local": 10})
    assert result == expect
Exemplo n.º 3
0
async def run_one_test_exception(test_data):
    """Run one interpreter test that generates an exception."""
    source, expect = test_data
    global_ctx = GlobalContext("test", global_sym_table={}, manager=GlobalContextMgr)
    ast = AstEval("test", global_ctx=global_ctx)
    Function.install_ast_funcs(ast)
    ast.parse(source)
    exc = ast.get_exception()
    if exc is not None:
        assert exc == expect
        return
    await ast.eval()
    exc = ast.get_exception()
    if exc is not None:
        assert exc == expect
        return
    assert False