Beispiel #1
0
def _check_tuples_equality(pypy_tuples, python_tuples, testname):
    # compare the two tuples by transforming them into AST, to hide irrelevant
    # differences -- typically newlines at the end of the tree.
    print 'Comparing the ASTs of', testname
    transformer1 = PyPyTransformer("")
    ast_pypy   = transformer1.compile_node(pypy_tuples)
    repr_pypy  = repr(ast_pypy)

    key = os.path.basename(testname)
    if key not in REAL_EXPECTED_OUTPUT:
        transformer2 = PythonTransformer()
        ast_python = transformer2.compile_node(python_tuples)
        repr_python = repr(ast_python)
    else:
        repr_python = REAL_EXPECTED_OUTPUT[key]

    if GRAMMAR_MISMATCH:
        # XXX hack:
        # hide the more common difference between 2.3 and 2.4, which is
        #   Function(None, ...)  where 'None' stands for no decorator in 2.4
        repr_pypy   = repr_pypy.replace("Function(None, ", "Function(")
        repr_python = repr_python.replace("Function(None, ", "Function(")
        # XXX hack(bis):
    #   we changed stablecompiler to use [] instead of () in several
    #   places (for consistency), so let's make sure the test won't fail
    #   because of that (the workaround is as drastic as the way we
    #   compare python and pypy tuples :-), but we'll change that with
    #   astbuilder.py
    repr_pypy = repr_pypy.replace("[]", "()")
    repr_python = repr_python.replace("[]", "()")
    # We also changed constants 'OP_ASSIGN' 'OP_DELETE' 'OP_APPLY' to use numeric values
    repr_python = repr_python.replace("'OP_ASSIGN'", repr(OP_ASSIGN) )
    repr_python = repr_python.replace("'OP_DELETE'", repr(OP_DELETE) )
    repr_python = repr_python.replace("'OP_APPLY'", repr(OP_APPLY) )

    assert repr_pypy == repr_python