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/java_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/java_code_evaluator.py')
-rw-r--r-- | yaksh/java_code_evaluator.py | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py index 167981b..9ec4209 100644 --- a/yaksh/java_code_evaluator.py +++ b/yaksh/java_code_evaluator.py @@ -15,6 +15,8 @@ class JavaCodeEvaluator(CodeEvaluator): def setup(self): super(JavaCodeEvaluator, self).setup() self.submit_code_path = self.create_submit_code_file('Test.java') + self.compiled_user_answer = None + self.compiled_test_code = None def teardown(self): super(JavaCodeEvaluator, self).teardown() @@ -34,7 +36,7 @@ class JavaCodeEvaluator(CodeEvaluator): return output_path 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 @@ -59,8 +61,18 @@ class JavaCodeEvaluator(CodeEvaluator): compile_command, self.compile_main = self.get_commands(clean_ref_code_path, user_code_directory) self.run_command_args = "java -cp {0} {1}".format(user_code_directory, ref_file_name) - self.compiled_output = self._compile_command(compile_command) - return self.compiled_output + # self.compiled_output = self._compile_command(compile_command) + self.compiled_user_answer = self._run_command(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 @@ -108,14 +120,19 @@ class JavaCodeEvaluator(CodeEvaluator): # ret = self._compile_command(compile_command) # proc, stdnt_stderr = ret 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 == '': |