Exemple #1
0
def test_as_ast_integer():
    if sys.version_info < (3, 8):
        assert "Num(n=1)" == ast.dump(as_ast(1))
    elif sys.version_info < (3, 9):
        assert "Constant(value=1, kind=None)" == ast.dump(as_ast(1))
    else:
        assert "Constant(value=1)" == ast.dump(as_ast(1))
Exemple #2
0
def test_as_ast_string_var():
    s = "hi there"
    if sys.version_info < (3, 8):
        assert "Str(s='hi there')" == ast.dump(as_ast(s))
    elif sys.version_info < (3, 9):
        assert "Constant(value='hi there', kind=None)" == ast.dump(as_ast(s))
    else:
        assert "Constant(value='hi there')" == ast.dump(as_ast(s))
Exemple #3
0
def test_as_ast_list():
    if sys.version_info < (3, 8):
        assert "List(elts=[Str(s='one'), Str(s='two')], ctx=Load())" == ast.dump(
            as_ast(["one", "two"]))
    elif sys.version_info < (3, 9):
        assert "List(elts=[Constant(value='one', kind=None), Constant(value='two', kind=None)], ctx=Load())" == ast.dump(
            as_ast(["one", "two"]))
    else:
        assert "List(elts=[Constant(value='one'), Constant(value='two')], ctx=Load())" == ast.dump(
            as_ast(["one", "two"]))
Exemple #4
0
def test_function_call_simple():
    a = function_call('dude', [as_ast(1)])
    print(ast.dump(ast.parse('dude(1)')))
    if sys.version_info < (3, 8):
        expected = "Call(func=Name(id='dude', ctx=Load()), args=[Num(n=1)], keywords=[])"
    elif sys.version_info < (3, 9):
        expected = "Call(func=Name(id='dude', ctx=Load()), args=[Constant(value=1, kind=None)], keywords=[])"
    else:
        expected = "Call(func=Name(id='dude', ctx=Load()), args=[Constant(value=1)], keywords=[])"
    assert expected == ast.dump(a)
Exemple #5
0
def test_as_ast_integer():
    assert "Num(n=1)" == ast.dump(as_ast(1))
Exemple #6
0
def test_function_call_simple():
    a = function_call('dude', [as_ast(1)])
    print(ast.dump(ast.parse('dude(1)')))
    expected = "Call(func=Name(id='dude', ctx=Load()), args=[Num(n=1)], keywords=[])"
    assert expected == ast.dump(a)
Exemple #7
0
def test_as_ast_list():
    assert "List(elts=[Str(s='one'), Str(s='two')], ctx=Load())" == ast.dump(
        as_ast(["one", "two"]))
Exemple #8
0
def test_as_ast_string_var():
    s = "hi there"
    assert "Str(s='hi there')" == ast.dump(as_ast(s))
Exemple #9
0
def test_as_ast_string():
    assert "Str(s='hi there')" == ast.dump(as_ast("hi there"))