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])
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())
def test_unrepr_globals_0(): assert unrepr("a", globals_d={"a": 102}) == 102
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)
def test_unrepr(param): assert unrepr(param.string) == param.expected
def test_unrepr_syntax_error_func_call_3(): with pytest.raises(SyntaxError) as exc_info: unrepr("import a", {})
def test_unrepr_syntax_error_func_call_2(): with pytest.raises(SyntaxError) as exc_info: unrepr("f(2, 3)", {})
def test_unrepr_syntax_error_func_call_1(): with pytest.raises(SyntaxError) as exc_info: unrepr("f(2, 3)", {'f': lambda: None})
def test_unrepr_syntax_error_func_call_0(): with pytest.raises(SyntaxError) as exc_info: unrepr("1(2, 3)")
def test_unrepr_syntax_error_undefined_binop(): with pytest.raises(SyntaxError) as exc_info: unrepr("1 << 2")