diff options
author | ankitjavalkar | 2016-04-21 17:31:09 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:16:26 +0530 |
commit | 5684b1b19fcb383f494f0bfc04ad1bb760abce74 (patch) | |
tree | 6d40b0cb151b9ab9d40d6c6479617f2eee5ed04b /yaksh/cpp_code_evaluator.py | |
parent | 2c7f278382f4fe8071508b0a880aae34f8edfd5e (diff) | |
download | online_test-5684b1b19fcb383f494f0bfc04ad1bb760abce74.tar.gz online_test-5684b1b19fcb383f494f0bfc04ad1bb760abce74.tar.bz2 online_test-5684b1b19fcb383f494f0bfc04ad1bb760abce74.zip |
Post review improvements:
- compiled_output is set during setup
- python exec context renamed
- _compile_command deprecated
Diffstat (limited to 'yaksh/cpp_code_evaluator.py')
-rw-r--r-- | yaksh/cpp_code_evaluator.py | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/yaksh/cpp_code_evaluator.py b/yaksh/cpp_code_evaluator.py index 250de8e..312467d 100644 --- a/yaksh/cpp_code_evaluator.py +++ b/yaksh/cpp_code_evaluator.py @@ -15,6 +15,8 @@ class CppCodeEvaluator(CodeEvaluator): def setup(self): super(CppCodeEvaluator, self).setup() self.submit_code_path = self.create_submit_code_file('submit.c') + self.compiled_user_answer = None + self.compiled_test_code = None def teardown(self): super(CppCodeEvaluator, self).teardown() @@ -37,7 +39,7 @@ class CppCodeEvaluator(CodeEvaluator): return compile_command, compile_main def compile_code(self, user_answer, test_case): - if hasattr(self, 'compiled_output'): + if self.compiled_user_answer and self.compiled_test_code: return None else: ref_code_path = test_case @@ -51,8 +53,19 @@ class CppCodeEvaluator(CodeEvaluator): self.write_to_submit_code_file(self.submit_code_path, user_answer) self.user_output_path, self.ref_output_path = self.set_file_paths() self.compile_command, self.compile_main = self.get_commands(clean_ref_code_path, self.user_output_path, self.ref_output_path) - self.compiled_output = self._compile_command(self.compile_command) - return self.compiled_output + # self.compiled_output = self._compile_command(self.compile_command) + self.compiled_user_answer = self._run_command(self.compile_command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + self.compiled_test_code = self._run_command(self.compile_main, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + + return self.compiled_user_answer, self.compiled_test_code def check_code(self, user_answer, test_case): """ Function validates student code using instructor code as @@ -89,17 +102,19 @@ class CppCodeEvaluator(CodeEvaluator): # ret = self._compile_command(compile_command) # proc, stdnt_stderr = ret # stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr) - success = False - proc, stdnt_stderr = self.compiled_output + proc, stdnt_out, stdnt_stderr = self.compiled_user_answer stdnt_stderr = self._remove_null_substitute_char(stdnt_stderr) - # Only if compilation is successful, the program is executed # And tested with testcases if stdnt_stderr == '': - ret = self._compile_command(self.compile_main) - proc, main_err = ret + # ret = self._compile_command(self.compile_main) + # ret = self._run_command(self.compile_main, + # shell=True, + # stdout=subprocess.PIPE, + # stderr=subprocess.PIPE) + proc, main_out, main_err = self.compiled_test_code main_err = self._remove_null_substitute_char(main_err) if main_err == '': |