diff options
author | maheshgudi | 2016-06-02 16:31:54 +0530 |
---|---|---|
committer | adityacp | 2016-07-27 22:52:23 +0530 |
commit | d14bf131d60af6eae6c3ff6ce5537af25420c314 (patch) | |
tree | 307ab45f8a05b6032b77c298d46d24fbbe4bf11f | |
parent | e46bd90fb2907a7a43786bee95985072e256cd56 (diff) | |
download | online_test-d14bf131d60af6eae6c3ff6ce5537af25420c314.tar.gz online_test-d14bf131d60af6eae6c3ff6ce5537af25420c314.tar.bz2 online_test-d14bf131d60af6eae6c3ff6ce5537af25420c314.zip |
renamed python_stdout_evaluation.py to python_stdio_evaluation.py
-rw-r--r-- | yaksh/python_stdout_evaluator.py | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/yaksh/python_stdout_evaluator.py b/yaksh/python_stdout_evaluator.py deleted file mode 100644 index 6606581..0000000 --- a/yaksh/python_stdout_evaluator.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -import sys -import traceback -import os -from os.path import join -import importlib -from contextlib import contextmanager - -# local imports -from code_evaluator import CodeEvaluator - - -@contextmanager -def redirect_stdout(): - from StringIO import StringIO - new_target = StringIO() - - old_target, sys.stdout = sys.stdout, new_target # replace sys.stdout - try: - yield new_target # run some code with the replaced stdout - finally: - sys.stdout = old_target # restore to the previous value - - -class PythonStdoutEvaluator(CodeEvaluator): - """Tests the Python code obtained from Code Server""" - - def compile_code(self, user_answer, expected_output): - if hasattr(self, 'output_value'): - return None - else: - submitted = compile(user_answer, '<string>', mode='exec') - with redirect_stdout() as output_buffer: - exec_scope = {} - exec submitted in exec_scope - self.output_value = output_buffer.getvalue() - return self.output_value - - def check_code(self, user_answer, expected_output): - success = False - - tb = None - if expected_output in user_answer: - success = False - err = ("Incorrect Answer: Please avoid " - "printing the expected output directly" - ) - elif self.output_value == expected_output: - success = True - err = "Correct answer" - - else: - success = False - err = "Incorrect Answer" - - del tb - return success, err - |