Esempio n. 1
0
    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]"
Esempio n. 2
0
 def test_expr_operators(self):
     a = py(1)
     assert repr(a) == "py(1)"
     assert str(a + 1) == "py['1 + 1']"
     assert str(a + 2) == "py['1 + 2']"
     assert str(a + a + a) == "py['1 + 1 + 1']"
     assert str(a.foo) == "py['(1).foo']"
Esempio n. 3
0
 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")
Esempio n. 4
0
 def test_expr_reversed_operators(self):
     a = py(1)
     assert str(2 + a) == "py['2 + 1']"
Esempio n. 5
0
 def test_containers(self):
     xs = unwrap(py([1, 2, 3]))
     assert len(xs.children) == 3
     assert xs.children[0] == Atom(1)