Example #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])
Example #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])
Example #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())
Example #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())
Example #5
0
def test_unrepr_globals_0():
    assert unrepr("a", globals_d={"a": 102}) == 102
Example #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)
Example #7
0
def test_unrepr(param):
    assert unrepr(param.string) == param.expected
Example #8
0
def test_unrepr_syntax_error_func_call_3():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("import a", {})
Example #9
0
def test_unrepr_syntax_error_func_call_2():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {})
Example #10
0
def test_unrepr_syntax_error_func_call_1():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {'f': lambda: None})
Example #11
0
def test_unrepr(param):
    assert unrepr(param.string) == param.expected
Example #12
0
def test_unrepr_syntax_error_func_call_1():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("f(2, 3)", {'f': lambda: None})
Example #13
0
def test_unrepr_syntax_error_func_call_0():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1(2, 3)")
Example #14
0
def test_unrepr_syntax_error_undefined_binop():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1 << 2")
Example #15
0
def test_unrepr_globals_0():
    assert unrepr("a", globals_d={"a": 102}) == 102
Example #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)
Example #17
0
def test_unrepr_syntax_error_undefined_binop():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("1 << 2")
Example #18
0
def test_unrepr_syntax_error_func_call_3():
    with pytest.raises(SyntaxError) as exc_info:
        unrepr("import a", {})