def test_wrapped_expressions(self): x = py.x y = py.y fn = py.fn src = lambda x: unwrap(x).source() assert src(x.foo) == "x.foo" assert src(fn(x)) == "fn(x)" assert src((x + y).method()) == "(x + y).method()"
def test_source(self): src = lambda x: unwrap(x).source() # Atoms assert src(py(42)) == "42" assert src(py(-42)) == "-42" # Containers assert src(py([])) == "[]" assert src(py([42])) == "[42]"
def test_free_vars(self): assert unwrap(py.x).free_vars() == {"x"} assert unwrap(py.x + py.y + 2).free_vars() == {"x", "y"}
def test_function_creation(self): fn = unwrap(py("def", py.func, [py.x], [py("return", (2 * py.x) + 1)])) assert fn.source() == "def func(x):\n return 2 * x + 1\n" assert fn.name.value == "func" assert isinstance(fn.args, Tree) assert fn.args.children[0] == Name("x")
def test_containers(self): xs = unwrap(py([1, 2, 3])) assert len(xs.children) == 3 assert xs.children[0] == Atom(1)
Function, Block, Lambda, GetItem, Slice, Compare, Tuple, List, Set, Dict, Del, ) from ox.target.python import to_expr, py, unwrap from ox.target.python.stmt_ast import Cmd src = lambda x: unwrap(x).source() class TestMetaClass: """ Check if class hierarchies are correct and metaclasses initialized everything nicely """ def test_mro(self): assert Atom._meta.root is Expr assert Return._meta.root is Stmt def test_expr_root(self): roles = Expr._meta.wrapper_roles sexpr = Expr._meta.sexpr_symbol_map assert {"getattr", "fcall"}.issubset(roles.keys())