From b59e11188609ef10150f76d75f75882f8ae20269 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 8 Dec 2016 14:41:49 +0530 Subject: Fix test cases to reflect code server and python evaluator changes --- yaksh/python_stdio_evaluator.py | 49 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 1506685..b618a0b 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -31,24 +31,36 @@ def redirect_stdout(): class PythonStdioEvaluator(CodeEvaluator): """Tests the Python code obtained from Code Server""" - def setup(self): - super(PythonStdioEvaluator, self).setup() + # def setup(self): + # super(PythonStdioEvaluator, self).setup() + # self.files = [] + + # def teardown(self): + # # Delete the created file. + # if self.files: + # delete_files(self.files) + # super(PythonStdioEvaluator, self).teardown() + def __init__(self, metadata, test_case_data): self.files = [] - def teardown(self): - # Delete the created file. - if self.files: - delete_files(self.files) - super(PythonStdioEvaluator, self).teardown() + # Set metadata values + self.user_answer = metadata.get('user_answer') + self.file_paths = metadata.get('file_paths') + self.partial_grading = metadata.get('partial_grading') + + # Set test case data values + self.expected_input = test_case_data.get('expected_input') + self.expected_output = test_case_data.get('expected_output') + self.weight = test_case_data.get('weight') - def compile_code(self, user_answer, file_paths, expected_input, expected_output, weight): - if file_paths: - self.files = copy_files(file_paths) - submitted = compile(user_answer, '', mode='exec') - if expected_input: + def compile_code(self): # user_answer, file_paths, expected_input, expected_output, weight): + if self.file_paths: + self.files = copy_files(self.file_paths) + submitted = compile(self.user_answer, '', mode='exec') + if self.expected_input: input_buffer = StringIO() - input_buffer.write(expected_input) + input_buffer.write(self.expected_input) input_buffer.seek(0) sys.stdin = input_buffer with redirect_stdout() as output_buffer: @@ -57,16 +69,15 @@ class PythonStdioEvaluator(CodeEvaluator): self.output_value = output_buffer.getvalue().rstrip("\n") return self.output_value - def check_code(self, user_answer, file_paths, partial_grading, expected_input, - expected_output, weight): + def check_code(self): # user_answer, file_paths, partial_grading, expected_input, expected_output, weight): success = False test_case_weight = 0.0 tb = None - if self.output_value == expected_output: + if self.output_value == self.expected_output: success = True err = "Correct answer" - test_case_weight = weight + test_case_weight = self.weight else: success = False err = dedent(""" @@ -74,8 +85,8 @@ class PythonStdioEvaluator(CodeEvaluator): Given input - {0} Expected output - {1} Your output - {2} - """.format(expected_input, - expected_output, + """.format(self.expected_input, + self.expected_output, self.output_value ) ) -- cgit From 80a4feef3c209e044e8cbe31e44c81d69136e100 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 15 Dec 2016 16:34:18 +0530 Subject: Add further changes to code evaluator --- yaksh/python_stdio_evaluator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index b618a0b..7ef3a7c 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -14,8 +14,8 @@ except ImportError: from io import StringIO # Local imports -from .code_evaluator import CodeEvaluator from .file_utils import copy_files, delete_files +from .base_evaluator import BaseEvaluator @contextmanager @@ -28,7 +28,7 @@ def redirect_stdout(): sys.stdout = old_target # restore to the previous value -class PythonStdioEvaluator(CodeEvaluator): +class PythonStdioEvaluator(BaseEvaluator): """Tests the Python code obtained from Code Server""" # def setup(self): -- cgit From f1da39aded67efa3da145851f0e9f687a3e434e5 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 11:44:55 +0530 Subject: Change all evaluator structure and make sure eval test cases pass --- yaksh/python_stdio_evaluator.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 7ef3a7c..991fd63 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -35,11 +35,6 @@ class PythonStdioEvaluator(BaseEvaluator): # super(PythonStdioEvaluator, self).setup() # self.files = [] - # def teardown(self): - # # Delete the created file. - # if self.files: - # delete_files(self.files) - # super(PythonStdioEvaluator, self).teardown() def __init__(self, metadata, test_case_data): self.files = [] @@ -53,6 +48,10 @@ class PythonStdioEvaluator(BaseEvaluator): self.expected_output = test_case_data.get('expected_output') self.weight = test_case_data.get('weight') + def teardown(self): + # Delete the created file. + if self.files: + delete_files(self.files) def compile_code(self): # user_answer, file_paths, expected_input, expected_output, weight): if self.file_paths: -- cgit From 4a0f94084bc26559ef3e26470619e87314f9d70e Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 19:18:35 +0530 Subject: Remove commented code --- yaksh/python_stdio_evaluator.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 991fd63..0f24a27 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -30,11 +30,6 @@ def redirect_stdout(): class PythonStdioEvaluator(BaseEvaluator): """Tests the Python code obtained from Code Server""" - - # def setup(self): - # super(PythonStdioEvaluator, self).setup() - # self.files = [] - def __init__(self, metadata, test_case_data): self.files = [] @@ -53,7 +48,7 @@ class PythonStdioEvaluator(BaseEvaluator): if self.files: delete_files(self.files) - def compile_code(self): # user_answer, file_paths, expected_input, expected_output, weight): + def compile_code(self): if self.file_paths: self.files = copy_files(self.file_paths) submitted = compile(self.user_answer, '', mode='exec') @@ -68,7 +63,7 @@ class PythonStdioEvaluator(BaseEvaluator): self.output_value = output_buffer.getvalue().rstrip("\n") return self.output_value - def check_code(self): # user_answer, file_paths, partial_grading, expected_input, expected_output, weight): + def check_code(self): success = False test_case_weight = 0.0 -- cgit From 798d36aa12e22928e884668ae5c80a25d48393ea Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 19 Dec 2016 19:37:23 +0530 Subject: Change weight variable name to mark_fraction --- yaksh/python_stdio_evaluator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 0f24a27..07bd59c 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -65,13 +65,13 @@ class PythonStdioEvaluator(BaseEvaluator): def check_code(self): success = False - test_case_weight = 0.0 + mark_fraction = 0.0 tb = None if self.output_value == self.expected_output: success = True err = "Correct answer" - test_case_weight = self.weight + mark_fraction = self.weight else: success = False err = dedent(""" @@ -85,4 +85,4 @@ class PythonStdioEvaluator(BaseEvaluator): ) ) del tb - return success, err, test_case_weight + return success, err, mark_fraction -- cgit From bf5b4e7607bae0b81ceeb99e8bf5d750433e92e8 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 20 Dec 2016 12:42:44 +0530 Subject: Fix errors and rename resources - code_evaluator module and class renamed to grader - Test cases fixed - Comments removed - weight variable renamed to mark --- yaksh/python_stdio_evaluator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/python_stdio_evaluator.py') diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index 07bd59c..da0c954 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -28,7 +28,7 @@ def redirect_stdout(): sys.stdout = old_target # restore to the previous value -class PythonStdioEvaluator(BaseEvaluator): +class PythonStdIOEvaluator(BaseEvaluator): """Tests the Python code obtained from Code Server""" def __init__(self, metadata, test_case_data): self.files = [] -- cgit