diff options
Diffstat (limited to 'yaksh/python_stdio_evaluator.py')
-rw-r--r-- | yaksh/python_stdio_evaluator.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/yaksh/python_stdio_evaluator.py b/yaksh/python_stdio_evaluator.py index aeec744..4a02267 100644 --- a/yaksh/python_stdio_evaluator.py +++ b/yaksh/python_stdio_evaluator.py @@ -9,7 +9,7 @@ from ast import literal_eval # local imports from code_evaluator import CodeEvaluator from StringIO import StringIO - +from file_utils import copy_files, delete_files from textwrap import dedent @contextmanager def redirect_stdout(): @@ -24,7 +24,17 @@ def redirect_stdout(): class PythonStdioEvaluator(CodeEvaluator): """Tests the Python code obtained from Code Server""" - def compile_code(self, user_answer, expected_input, expected_output): + def teardown(self): + super(PythonStdioEvaluator, self).teardown() + # Delete the created file. + if self.files: + delete_files(self.files) + + + def compile_code(self, user_answer, file_paths, expected_input, expected_output): + self.files = [] + if file_paths: + self.files = copy_files(file_paths) submitted = compile(user_answer, '<string>', mode='exec') if expected_input: input_buffer = StringIO() @@ -37,7 +47,7 @@ class PythonStdioEvaluator(CodeEvaluator): self.output_value = output_buffer.getvalue().rstrip("\n") return self.output_value - def check_code(self, user_answer, expected_input, expected_output): + def check_code(self, user_answer, file_paths, expected_input, expected_output): success = False tb = None @@ -47,10 +57,11 @@ class PythonStdioEvaluator(CodeEvaluator): else: success = False err = dedent(""" - Incorrect Answer: - Given input - {0}, - Expected output - {1} and your output - {2} - """ + Incorrect Answer: + Given input - {0} + Expected output - {1} + Your output - {2} + """ .format(expected_input, expected_output, self.output_value ) |