def check_ast(code, ref, optimizations): """ Check if a final node is the same as expected. Parameters ---------- code : str code we want to check after refine and optimizations ref : str The expected dump for the AST optimizations : [optimization] list of optimisation to apply Raises ------ is_same : AssertionError Raise if the result is not the one expected. """ pm = PassManager("testing") ir, _, _ = frontend.parse(pm, code) optimizations = [_parse_optimization(opt) for opt in optimizations] refine(pm, ir, optimizations) content = pm.dump(Python, ir) if content != ref: raise AssertionError( "AST is not the one expected. Reference was %s," "but received %s" % (repr(ref), repr(content)))
def check_ast(code, ref, optimizations): """ Check if a final node is the same as expected. Parameters ---------- code : str code we want to check after refine and optimizations ref : str The expected dump for the AST optimizations : [optimization] list of optimisation to apply Raises ------ is_same : AssertionError Raise if the result is not the one expected. """ pm = PassManager("testing") ir, _, _ = frontend.parse(pm, code) optimizations = [_parse_optimization(opt) for opt in optimizations] refine(pm, ir, optimizations) content = pm.dump(Python, ir) if content != ref: raise AssertionError( "AST is not the one expected. Reference was %s," "but received %s" % (repr(ref), repr(content)))