from interpreter_utils import * import ast import inspect from py_demo_unparse import Unparser def test_ast_bin_op_to_ast_expression(): op = ast.Add expr = interpreter_utils._ast_bin_op_to_ast_expression(op) print("Dump:") print(ast.dump(expr)) print("Unparse:") Unparser(expr) print() code = compile_expr_to_code(expr) f = eval(code) assert callable(f) y = f(5, 7) assert y == 12 def test_ast_bin_op_to_func_add(): op = ast.Add f = ast_bin_op_to_func(op) y = f(5, 7) assert y == 12 if __name__ == "__main__": main(globals())
# parent os.close(pipes[0][0]) os.close(pipes[1][1]) child_stdout = os.fdopen(pipes[1][0], "rb", 0) child_stdout = child_stdout.readlines() if PY3: child_stdout = [l.decode("utf8") for l in child_stdout] expected_out = [ "Hello world\n", "args: 2\n", "./test\n", "abc\n", "Normal exit.\n", ] if expected_out != child_stdout: print("Got output:") print("".join(child_stdout)) dump() print("run directly here now:") interp.runFunc("main", 2, ["./test", "abc", None]) raise Exception("child stdout %r" % (child_stdout,)) if __name__ == '__main__': helpers_test.main(globals())