diff options
author | maheshgudi | 2016-08-03 15:16:08 +0530 |
---|---|---|
committer | maheshgudi | 2016-08-03 15:16:08 +0530 |
commit | 40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb (patch) | |
tree | 7885b674d2deb064137f1f501ed1707bfd54daf8 /yaksh/python_stdio_evaluator.py | |
parent | 1b71abc9437d721a41f017db406f312755f5a4c4 (diff) | |
parent | 2b03aeb36fa333ea1644a248c742cf0c1df12a5f (diff) | |
download | online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.gz online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.tar.bz2 online_test-40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb.zip |
rebase changes with stdio evaluator
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 ) |