summaryrefslogtreecommitdiff
path: root/yaksh/scilab_code_evaluator.py
diff options
context:
space:
mode:
authorankitjavalkar2016-04-18 15:22:25 +0530
committerankitjavalkar2016-05-05 19:16:26 +0530
commit2c7f278382f4fe8071508b0a880aae34f8edfd5e (patch)
tree3268bd3b29bf7e0148ca818c25c128bd0d38a944 /yaksh/scilab_code_evaluator.py
parentd3241512c71d61b355358a691d18e4ff8a8df34c (diff)
downloadonline_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.tar.gz
online_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.tar.bz2
online_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.zip
add compile_code function to compile before checking
Diffstat (limited to 'yaksh/scilab_code_evaluator.py')
-rw-r--r--yaksh/scilab_code_evaluator.py67
1 files changed, 46 insertions, 21 deletions
diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py
index 61642fd..87c0e1e 100644
--- a/yaksh/scilab_code_evaluator.py
+++ b/yaksh/scilab_code_evaluator.py
@@ -33,27 +33,52 @@ class ScilabCodeEvaluator(CodeEvaluator):
# Delete the created file.
os.remove(self.submit_code_path)
- def check_code(self, user_answer, test_case):
- ref_code_path = test_case
- clean_ref_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
- user_answer, terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
+ def compile_code(self, user_answer, test_case):
+ if hasattr(self, 'compiled_output'):
+ return None
+ else:
+ ref_code_path = test_case
+ clean_ref_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
+ user_answer, terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
+
+ self.write_to_submit_code_file(self.submit_code_path, user_answer)
+ # Throw message if there are commmands that terminates scilab
+ self.add_err = ""
+ if terminate_commands:
+ self.add_err = "Please do not use exit, quit and abort commands in your\
+ code.\n Otherwise your code will not be evaluated\
+ correctly.\n"
+
+ cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(clean_ref_path)
+ cmd += ' | timeout 8 scilab-cli -nb'
+ self.compiled_output = self._run_command(cmd,
+ shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ return self.compiled_output
+ def check_code(self, user_answer, test_case):
+ # ref_code_path = test_case
+ # clean_ref_path, clean_test_case_path = self._set_test_code_file_path(ref_code_path)
+ # user_answer, terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
+
+ # success = False
+ # self.write_to_submit_code_file(self.submit_code_path, user_answer)
+ # # Throw message if there are commmands that terminates scilab
+ # add_err = ""
+ # if terminate_commands:
+ # add_err = "Please do not use exit, quit and abort commands in your\
+ # code.\n Otherwise your code will not be evaluated\
+ # correctly.\n"
+
+ # cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(clean_ref_path)
+ # cmd += ' | timeout 8 scilab-cli -nb'
+ # ret = self._run_command(cmd,
+ # shell=True,
+ # stdout=subprocess.PIPE,
+ # stderr=subprocess.PIPE)
success = False
- self.write_to_submit_code_file(self.submit_code_path, user_answer)
- # Throw message if there are commmands that terminates scilab
- add_err=""
- if terminate_commands:
- add_err = "Please do not use exit, quit and abort commands in your\
- code.\n Otherwise your code will not be evaluated\
- correctly.\n"
-
- cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(clean_ref_path)
- cmd += ' | timeout 8 scilab-cli -nb'
- ret = self._run_command(cmd,
- shell=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- proc, stdout, stderr = ret
+ proc, stdout, stderr = self.compiled_output
# Get only the error.
stderr = self._get_error(stdout)
@@ -63,9 +88,9 @@ class ScilabCodeEvaluator(CodeEvaluator):
if proc.returncode == 5:
success, err = True, "Correct answer"
else:
- err = add_err + stdout
+ err = self.add_err + stdout
else:
- err = add_err + stderr
+ err = self.add_err + stderr
return success, err