def testMyCode(self, *args): self.console.clear() if not self.compile(no_debug=True): return compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) test_command = "{}".format( " ".join(util.exec_command(self.editor.lang) + [compiled_file]) ) command = ["oj", "test", "-c", test_command] print(command) if self.exists_float_output(): error = 0.00000001 command += ["-e", str(error)] self.console.writeLnSignal.emit("[.] Found float expectation") self.console.writeLnSignal.emit("[.] Allow {} error".format(error)) self.recorder.push(self.browser_widget.browser.url().toString(), "test") try: out = subprocess.check_output( command, stderr=subprocess.STDOUT, timeout=4.0 ).decode() self.console.writeLnSignal.emit(out) except subprocess.TimeoutExpired as e: self.console.writeLnSignal.emit(e.output) self.console.writeLnSignal.emit("[-] Test is Timeout") return except subprocess.CalledProcessError as e: self.console.writeLnSignal.emit(e.output) except Exception as e: self.console.writeSignal.emit(WriteObj(e, mode="error")) return
def run(self): if self.debug_process is not None: if self.askTerminateOrNot(): self.terminate() else: return if not self.compile(no_debug=True): return self.updateWindowTitle(True) compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) if not os.path.isfile(compiled_file): util.disp_error("Compiled file is not found.") try: output = subprocess.check_output( util.exec_command(self.editor.lang) + [compiled_file], stderr=subprocess.STDOUT, ) self.console.writeLnSignal.emit(output) except subprocess.CalledProcessError as err: self.console.writeLnSignal.emit("[-] " + err.output.decode()) self.console.writeLnSignal.emit("[-] Run process is terminated abnormally.") self.updateWindowTitle(False) return self.console.writeLnSignal.emit("[+] Run process is finished successfully!") self.updateWindowTitle(False)
def testMyCode(self, *args): self.console.clear() if not self.compile(no_debug=True): return compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) test_command = "{}".format( " ".join(util.exec_command(self.editor.lang) + [compiled_file])) try: command = ["oj", "test", "-c", test_command] print(command) if self.exists_float_output(): error = 0.00000001 command += ["-e", str(error)] self.console.write_oj_result("[.] Found float expectation") self.console.write_oj_result( "[.] Allow {} error".format(error)) # TODO: configurable timeout out = subprocess.check_output(command, stderr=subprocess.STDOUT, timeout=4.0).decode() except subprocess.TimeoutExpired as e: self.console.write_oj_result(e.output) self.console.write_oj_result("[-] Test is Timeout") return except Exception as e: self.console.write_oj_result(e.output) return self.console.write_oj_result(out)
def testReactive(self, *args): self.console.clear() if not self.compile(no_debug=True): return compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) test.TestReactiveDialog( self, compiled_file=compiled_file, settings=self.settings ).show()
def debug(self, *args, **kwargs): self.console.clear() if not self.compile(): return if self.debug_process is not None: if self.askTerminateOrNot(): self.terminate() else: return compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) if not os.path.isfile(compiled_file): util.disp_error("Compiled file is not found.") try: assert self.debug_process is None self.debug_process = pexpect.spawn( util.debug_command(self.editor.lang) + " " + compiled_file ) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit(WriteObj(self.debug_process.before.decode())) for com in self.editor.generateBreak(): self.debug_process.send(com) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit( WriteObj(self.debug_process.before.decode(), mode="gdb") ) print("run " + compiled_file) self.debug_process.send(b"run\n") self.updateWindowTitle() if self.editor.lang == "python3": util.wait_input_ready(self.debug_process, self.editor.lang) self.debug_process.send(b"continue\n") self.post_process() except subprocess.CalledProcessError as err: self.console.writeSignal(WriteObj(err, mode="error"))
def debugWithTestData(self, use_lastcase=False): self.console.clear() if not self.compile(): return if self.debug_process is not None: if self.askTerminateOrNot(): self.terminate() else: return if ( use_lastcase and self.last_used_testcase and os.path.isfile(self.last_used_testcase) ): fname = self.last_used_testcase else: fname = QtWidgets.QFileDialog.getOpenFileName( self, "Open", self.test_data_dir, "Test data (*.in)" )[0] if not fname: self.last_used_testcase = "" return self.last_used_testcase = fname with open(fname) as fr: inputs = [line for line in fr if line] compiled_file = util.get_compiled_file(self.editor.lang, self.editor.fname) if not os.path.isfile(compiled_file): util.disp_error("Compiled file is not found.") try: if self.debug_process is None: self.debug_process = pexpect.spawn( util.debug_command(self.editor.lang) + " " + compiled_file ) self.console.terminate_evcxr() else: self.continue_process() return util.wait_input_ready(self.debug_process, self.editor.lang) for com in self.editor.generateBreak(): self.debug_process.send(com) util.wait_input_ready(self.debug_process, self.editor.lang) self.console.writeSignal.emit( WriteObj(self.debug_process.before.decode(), mode="gdb") ) print("run " + compiled_file) self.debug_process.send(b"run\n") self.updateWindowTitle() if self.editor.lang == "python3": util.wait_input_ready(self.debug_process, self.editor.lang) self.debug_process.send(b"continue\n") for i, debug_input in enumerate(inputs): msg = self.debug_process.before.decode() for line in msg.split("\r\n"): self.console.writeSignal.emit(WriteObj(line, mode="gdb")) for line in reversed(msg.split("\r\n")): if line.endswith("exited normally]"): if i != len(inputs) - 1: self.console.writeLnSignal.emit( "[-] Partial input is rejected" ) self.terminate() return if "exited with code" in line: self.console.writeLnSignal.emit( "[-] Process is finished with error" ) self.terminate() return self.debug_process.send(debug_input.encode()) self.post_process() self.updateWindowTitle() self.console.run_evcxr() except subprocess.CalledProcessError as err: self.console.writeSignal.emit(WriteObj(err, mode="error")) self.console.run_evcxr()