Exemplo n.º 1
0
def test_unrepr_globals_1():
    def myfun(x, y, l):
        return x + y + len(l)

    A_VALUE = 100
    gd = {
        'myfunction': myfun,
        'a': A_VALUE,
    }
    string = "myfunction(10, y=a, l=[1, 2, 3])"
    assert unrepr(string, globals_d=gd) == 10 + A_VALUE + len([1, 2, 3])
Exemplo n.º 2
0
def test_unrepr_globals_1():
    def myfun(x, y, l):
        return x + y + len(l)

    A_VALUE = 100
    gd = {
        'myfunction': myfun,
        'a': A_VALUE,
    }
    string = "myfunction(10, y=a, l=[1, 2, 3])"
    assert unrepr(string, globals_d=gd) == 10 + A_VALUE + len([1, 2, 3])
Exemplo n.º 3
0
def test_unrepr_globals():
    def myfun(z1, z2, z3, x1, x2, x3):
        return z1 + z2 + z3 + x1 + x2 + x3

    l1 = [100, 200, 300]
    d1 = {'x1': 1000, 'x2': 2000, 'x3': 3000}
    gd = {
        'myfunction': myfun,
        'l1': l1,
        'd1': d1,
    }
    string = "myfunction(*l1, **d1)"
    assert unrepr(string, globals_d=gd) == sum(l1) + sum(d1.values())
Exemplo n.º 4
0
def test_unrepr_globals():
    def myfun(z1, z2, z3, x1, x2, x3):
        return z1 + z2 + z3 + x1 + x2 + x3

    l1 = [100, 200, 300]
    d1 = {'x1': 1000, 'x2': 2000, 'x3': 3000}
    gd = {
        'myfunction': myfun,
        'l1': l1,
        'd1': d1,
    }
    string = "myfunction(*l1, **d1)"
    assert unrepr(string, globals_d=gd) == sum(l1) + sum(d1.values())
Exemplo n.º 5
0
def test_unrepr_globals_0():
    assert unrepr("a", globals_d={"a": 102}) == 102
Exemplo n.º 6
0
def test_unrepr_failure(bad_param):
    with pytest.raises(type(bad_param.expected)) as exc_info:
        unrepr(bad_param.string)
    assert str(exc_info.value) == str(bad_param.expected)
Exemplo n.º 7
0
def test_unrepr(param):
    assert unrepr(param.string) == param.expected
Exemplo n.º 8
0
def test_unrepr_syntax_error_func_call_3():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("import a", {})
Exemplo n.º 9
0
def test_unrepr_syntax_error_func_call_2():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {})
Exemplo n.º 10
0
def test_unrepr_syntax_error_func_call_1():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {'f': lambda: None})
Exemplo n.º 11
0
def test_unrepr(param):
    assert unrepr(param.string) == param.expected
Exemplo n.º 12
0
def test_unrepr_syntax_error_func_call_1():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {'f': lambda: None})
Exemplo n.º 13
0
def test_unrepr_syntax_error_func_call_0():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1(2, 3)")
Exemplo n.º 14
0
def test_unrepr_syntax_error_undefined_binop():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1 << 2")
Exemplo n.º 15
0
def test_unrepr_globals_0():
    assert unrepr("a", globals_d={"a": 102}) == 102
Exemplo n.º 16
0
def test_unrepr_failure(bad_param):
    with pytest.raises(type(bad_param.expected)) as exc_info:
        unrepr(bad_param.string)
    assert str(exc_info.value) == str(bad_param.expected)
Exemplo n.º 17
0
def test_unrepr_syntax_error_undefined_binop():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1 << 2")
Exemplo n.º 18
0
def test_unrepr_syntax_error_func_call_3():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("import a", {})