From 3b56d8259d6aa8311f86e0561e40d0b17bc62534 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 4 Mar 2016 14:55:09 +0530 Subject: Language registry altered, Name cleanup: - set_registry will only act when registry is None - _setup, _teardown and _check_code are setup,teardown,check_code - Corresponding name changes in evaluator modules --- yaksh/scilab_code_evaluator.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 392cd45..a8bd4cd 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -20,23 +20,22 @@ class ScilabCodeEvaluator(CodeEvaluator): # 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() + self.test_case_args = self.setup() - # Private Protocol ########## - def _setup(self): - super(ScilabCodeEvaluator, 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 - def _teardown(self): + def teardown(self): # Delete the created file. - super(ScilabCodeEvaluator, self)._teardown() + super(ScilabCodeEvaluator, self).teardown() os.remove(self.submit_path) - def _check_code(self, ref_path): + def check_code(self, ref_path): success = False # Throw message if there are commmands that terminates scilab -- cgit From e8e6b4bc35c7d012d9c41fb37d91687eb605b56c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 29 Mar 2016 19:00:12 +0530 Subject: - 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 --- yaksh/scilab_code_evaluator.py | 72 +++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') 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 -- cgit From d3241512c71d61b355358a691d18e4ff8a8df34c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 6 Apr 2016 11:26:52 +0530 Subject: Multiple test cases passed as dicts, check_code() is iterated based on no. of test cases --- yaksh/scilab_code_evaluator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 6ddfa5a..61642fd 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -33,8 +33,8 @@ class ScilabCodeEvaluator(CodeEvaluator): # Delete the created file. os.remove(self.submit_code_path) - def check_code(self, user_answer, test_case_data): - ref_code_path = test_case_data[0] + 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()) -- cgit From 2c7f278382f4fe8071508b0a880aae34f8edfd5e Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 18 Apr 2016 15:22:25 +0530 Subject: add compile_code function to compile before checking --- yaksh/scilab_code_evaluator.py | 67 +++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 21 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') 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 -- cgit From 5684b1b19fcb383f494f0bfc04ad1bb760abce74 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 21 Apr 2016 17:31:09 +0530 Subject: Post review improvements: - compiled_output is set during setup - python exec context renamed - _compile_command deprecated --- yaksh/scilab_code_evaluator.py | 91 ++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 44 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 87c0e1e..fedfab3 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -33,52 +33,53 @@ class ScilabCodeEvaluator(CodeEvaluator): # Delete the created file. os.remove(self.submit_code_path) - 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 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()) + 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 - proc, stdout, stderr = self.compiled_output + 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 + # proc, stdout, stderr = self.compiled_output + proc, stdout, stderr = ret # Get only the error. stderr = self._get_error(stdout) @@ -88,9 +89,11 @@ class ScilabCodeEvaluator(CodeEvaluator): if proc.returncode == 5: success, err = True, "Correct answer" else: - err = self.add_err + stdout + # err = self.add_err + stdout + err = add_err + stdout else: - err = self.add_err + stderr + # err = self.add_err + stderr + err = add_err + stderr return success, err -- cgit From 23b7abd3c1125e4c875e214e4f673c48c4bf4752 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 2 May 2016 11:52:58 +0530 Subject: Remove commented code and cleanup --- yaksh/scilab_code_evaluator.py | 68 ------------------------------------------ 1 file changed, 68 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index fedfab3..3af9782 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -12,16 +12,6 @@ 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) - - # # 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) @@ -33,30 +23,6 @@ class ScilabCodeEvaluator(CodeEvaluator): # Delete the created file. os.remove(self.submit_code_path) - # 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) @@ -89,46 +55,12 @@ class ScilabCodeEvaluator(CodeEvaluator): if proc.returncode == 5: success, err = True, "Correct answer" else: - # err = self.add_err + stdout err = add_err + stdout else: - # err = self.add_err + stderr err = add_err + stderr 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 -- cgit From d953f6f9e62671eeb5d6ea6498475167301dfe91 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 2 May 2016 14:38:13 +0530 Subject: - Fix tests - Fix minor views.py - Fix minor errors caused due to conflict resolution, rebasing - Fix errors in forms, views - Minor Button label change in addquestion.html - Add snippet to question - Remove commented code --- yaksh/scilab_code_evaluator.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index 3af9782..f4aa5f8 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -14,9 +14,7 @@ class ScilabCodeEvaluator(CodeEvaluator): """Tests the Scilab code obtained from Code Server""" def setup(self): super(ScilabCodeEvaluator, self).setup() - # 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): super(ScilabCodeEvaluator, self).teardown() @@ -43,8 +41,6 @@ class ScilabCodeEvaluator(CodeEvaluator): shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # success = False - # proc, stdout, stderr = self.compiled_output proc, stdout, stderr = ret # Get only the error. -- cgit From c384c60c6d7fb5d30f3f929c518e0b41e084c4c4 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 9 May 2016 13:00:04 +0530 Subject: - Adhere to 80 columns - add docstrings - Fix further tests --- yaksh/scilab_code_evaluator.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'yaksh/scilab_code_evaluator.py') diff --git a/yaksh/scilab_code_evaluator.py b/yaksh/scilab_code_evaluator.py index f4aa5f8..91b4cb3 100644 --- a/yaksh/scilab_code_evaluator.py +++ b/yaksh/scilab_code_evaluator.py @@ -14,7 +14,8 @@ class ScilabCodeEvaluator(CodeEvaluator): """Tests the Scilab code obtained from Code Server""" def setup(self): super(ScilabCodeEvaluator, self).setup() - self.submit_code_path = self.create_submit_code_file('function.sci') + self.submit_code_path = \ + self.create_submit_code_file('function.sci') def teardown(self): super(ScilabCodeEvaluator, self).teardown() @@ -23,8 +24,10 @@ class ScilabCodeEvaluator(CodeEvaluator): 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()) + 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) @@ -35,12 +38,15 @@ class ScilabCodeEvaluator(CodeEvaluator): code.\n Otherwise your code will not be evaluated\ correctly.\n" - cmd = 'printf "lines(0)\nexec(\'{0}\',2);\nquit();"'.format(clean_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, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) proc, stdout, stderr = ret # Get only the error. -- cgit