def check_transformer_output(src_fname):
    src = resources.read_text(restricted_transformer_data, src_fname)
    expected_src = resources.read_text(restricted_transformer_data,
                                       src_fname + ".res")

    c_ast = ast.parse(src, "<file>", "exec")

    collected_errors = []

    policy = PyriRestrictingNodeTransformer

    policy_instance = policy(collected_errors)
    policy_instance.visit(c_ast)
    if (len(collected_errors) > 0):
        print(collected_errors)
        raise Exception("Got errors")

    run_transformer(src)

    expected_c_ast = ast.parse(expected_src, "<file>", "exec")

    # Run c_ast through the decompiler to have matching formats
    c_ast2 = ast.parse(astor.to_source(c_ast), "<file 2>", "exec")

    astdiff.compare_ast(c_ast2, expected_c_ast)
def test_compare_sets(ast_set1, ast_set2):
    with pytest.raises(AssertionError):
        compare_ast(ast_set1, ast_set2, 0, 0)
def test_compare_formatting(ast_a1, ast_a2):
    assert compare_ast(ast_a1, ast_a2, 0, 0) is None
def test_compare_different_formatting(ast_a1, ast_b1):
    with pytest.raises(AssertionError):
        compare_ast(ast_a1, ast_b1, 0, 0)
def test_compare_different_nodes():
    node1 = ast.parse("x = 1")
    node2 = ast.parse("y = 1")
    with pytest.raises(AssertionError):
        compare_ast(node1, node2, 0, 0)
def test_compare_equal_nodes():
    node = ast.parse("x = 0")
    assert compare_ast(node, node, 0, 0) is None
def test_compare_different_length_lists():
    with pytest.raises(AssertionError):
        assert compare_ast(["foo"], ["spam", "eggs"], 0, 0)
def test_compare_equal_lists():
    assert compare_ast([], [], 0, 0) is None
    assert compare_ast(["foo", "bar"], ["foo", "bar"], 0, 0) is None
def test_compare_equal_strings():
    assert compare_ast("foo", "foo", 0, 0) is None