summaryrefslogtreecommitdiff
path: root/yaksh/scilab_code_evaluator.py
diff options
context:
space:
mode:
authorankitjavalkar2016-03-29 19:00:12 +0530
committerankitjavalkar2016-05-05 19:00:33 +0530
commite8e6b4bc35c7d012d9c41fb37d91687eb605b56c (patch)
tree2f0488eaed410e23a5d0e0a18b9bdae1e2b2f2d1 /yaksh/scilab_code_evaluator.py
parent1f4542cdbea66899899b9c7de3ea38e39d794112 (diff)
downloadonline_test-e8e6b4bc35c7d012d9c41fb37d91687eb605b56c.tar.gz
online_test-e8e6b4bc35c7d012d9c41fb37d91687eb605b56c.tar.bz2
online_test-e8e6b4bc35c7d012d9c41fb37d91687eb605b56c.zip
- Refactor Scilab, Bash, Java and C
- Add Test Cases to reflect refactoring changes - Fix language registry - Add test case for language registry - Fix register in settings - Keep snippet field for now
Diffstat (limited to 'yaksh/scilab_code_evaluator.py')
-rw-r--r--yaksh/scilab_code_evaluator.py72
1 files changed, 53 insertions, 19 deletions
diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py
index a8bd4cd..6ddfa5a 100644
--- a/yaksh/scilab_code_evaluator.py
+++ b/yaksh/scilab_code_evaluator.py
@@ -12,40 +12,42 @@ from code_evaluator import CodeEvaluator
class ScilabCodeEvaluator(CodeEvaluator):
"""Tests the Scilab code obtained from Code Server"""
- def __init__(self, test_case_data, test, language, user_answer,
- ref_code_path=None, in_dir=None):
- super(ScilabCodeEvaluator, self).__init__(test_case_data, test,
- language, user_answer,
- ref_code_path, in_dir)
+ # def __init__(self, test_case_data, test, language, user_answer,
+ # ref_code_path=None, in_dir=None):
+ # super(ScilabCodeEvaluator, self).__init__(test_case_data, test,
+ # language, user_answer,
+ # ref_code_path, in_dir)
- # Removes all the commands that terminates scilab
- self.user_answer, self.terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
- self.test_case_args = self.setup()
+ # # Removes all the commands that terminates scilab
+ # self.user_answer, self.terminate_commands = self._remove_scilab_exit(user_answer.lstrip())
+ # self.test_case_args = self.setup()
def setup(self):
super(ScilabCodeEvaluator, self).setup()
-
- ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
- self.submit_path = self.create_submit_code_file('function.sci')
-
- return ref_path, # Return as a tuple
+ # ref_path, test_case_path = self._set_test_code_file_path(self.ref_code_path)
+ self.submit_code_path = self.create_submit_code_file('function.sci')
+ # return ref_path, # Return as a tuple
def teardown(self):
- # Delete the created file.
super(ScilabCodeEvaluator, self).teardown()
- os.remove(self.submit_path)
+ # Delete the created file.
+ os.remove(self.submit_code_path)
- def check_code(self, ref_path):
- success = False
+ def check_code(self, user_answer, test_case_data):
+ ref_code_path = test_case_data[0]
+ 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 self.terminate_commands:
+ 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(ref_path)
+ 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,
@@ -67,6 +69,38 @@ class ScilabCodeEvaluator(CodeEvaluator):
return success, err
+ # def check_code(self, ref_path):
+ # success = False
+
+ # # Throw message if there are commmands that terminates scilab
+ # add_err=""
+ # if self.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(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
+
+ # # Get only the error.
+ # stderr = self._get_error(stdout)
+ # if stderr is None:
+ # # Clean output
+ # stdout = self._strip_output(stdout)
+ # if proc.returncode == 5:
+ # success, err = True, "Correct answer"
+ # else:
+ # err = add_err + stdout
+ # else:
+ # err = add_err + stderr
+
+ # return success, err
+
def _remove_scilab_exit(self, string):
"""
Removes exit, quit and abort from the scilab code