From eb201f2afe8a461bf7d094e27b193b5d05712e49 Mon Sep 17 00:00:00 2001 From: Rahul Arya Date: Mon, 15 Apr 2019 04:22:03 -0700 Subject: [PATCH] Made some recursive procedures iterative. (#155) --- editor/local_server.py | 2 +- editor/ok_interface.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/editor/local_server.py b/editor/local_server.py index 08c5a58b..6c9400cc 100644 --- a/editor/local_server.py +++ b/editor/local_server.py @@ -81,7 +81,7 @@ def handle_post_thread(self, data, path): elif path == "/test": self.cancellation_event.clear() # Make sure we don't have lingering cancellation requests from before output = cancelable_subprocess_call(self.cancellation_event, (sys.argv[0], os.path.splitext(ok_interface.__file__)[0] + ".py"), -1, sys.executable, subprocess.PIPE, subprocess.PIPE, None) - self.wfile.write(output) + self.wfile.write(output.split(ok_interface.BEGIN_OUTPUT)[1]) elif path == "/list_files": self.wfile.write(bytes(json.dumps(get_scm_files()), "utf-8")) diff --git a/editor/ok_interface.py b/editor/ok_interface.py index 3c6417a9..950aa700 100644 --- a/editor/ok_interface.py +++ b/editor/ok_interface.py @@ -15,14 +15,17 @@ FAILURE_SETUP_FOOTER = "; Raw ok output over" +BEGIN_OUTPUT = b"sdfghjkjhgfdfghjklkjhgfdxcfghj" + class PrintCapture: - def __init__(self): + def __init__(self, old_stdout): self.log = [] + self.old_stdout = old_stdout def write(self, message): self.log.append(message) - sys.__stdout__.write(message) + self.old_stdout.write(message) def flush(self): sys.__stdout__.flush() @@ -30,7 +33,7 @@ def flush(self): def capture_output(console, lines): old_stdout = sys.stdout - sys.stdout = out = PrintCapture() + sys.stdout = out = PrintCapture(old_stdout) result = console._interpret_lines(lines) sys.stdout = old_stdout if str(TerminatedError()) in "".join(out.log): @@ -173,8 +176,8 @@ def process(output, success): return Locked() else: return AreDifferent("\n".join(prompt), expected, actual) - elif "Traceback" in result or "# Error:" in result: - return Error("\n".join(prompt).strip("\n"), result) + # elif "Traceback" in result or "# Error:" in result: + # return Error("\n".join(prompt).strip("\n"), result) else: return Same("\n".join(prompt), result.strip()) @@ -259,14 +262,14 @@ def run_tests(): except TerminatedError: return [{'problem': "Tests Terminated by User", 'suites': [], 'passed': False}] + if __name__ == '__main__': output = None - with open(os.devnull, 'wb') as null: - with redirect_descriptor(sys.stdout, null): - sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "ok")) - try: - output = run_tests() - finally: - sys.path.pop(0) + sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "ok")) + try: + output = run_tests() + finally: + sys.path.pop(0) import json + print(BEGIN_OUTPUT.decode("ascii")) json.dump(output, sys.stdout)