def has_same_result(source_path, ref_path, verbose=False, print_ast=False): with open(source_path, 'r') as f_source, open(ref_path, 'r') as f_ref: source = f_source.read() reference = f_ref.read() # Pipe stdout to a variable old_stdout = sys.stdout sys.stdout = mystdout = StringIO() try: run(source, verbose=verbose, print_ast=print_ast) result = mystdout.getvalue() except Exception as e: raise e finally: sys.stdout = old_stdout if verbose or result != reference: print('') print(source_path) print(result) print(reference) return result == reference
def test_constant_int(): run('42;')
def test_identifier(): ns = {'a': 42} run('a;', ns)
def assert_res(source, variables={}, verbose=False, print_ast=False): ns = {} run(source, ns, verbose, print_ast) for key, value in variables.items(): eq_(ns.get(key, None), value)
def test_identifier(): ns = {'a' : 42} run('a;', ns)