summaryrefslogtreecommitdiff
path: root/yaksh/python_stdout_evaluator.py
diff options
context:
space:
mode:
authorankitjavalkar2016-04-18 15:22:25 +0530
committerankitjavalkar2016-05-05 19:16:26 +0530
commit2c7f278382f4fe8071508b0a880aae34f8edfd5e (patch)
tree3268bd3b29bf7e0148ca818c25c128bd0d38a944 /yaksh/python_stdout_evaluator.py
parentd3241512c71d61b355358a691d18e4ff8a8df34c (diff)
downloadonline_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.tar.gz
online_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.tar.bz2
online_test-2c7f278382f4fe8071508b0a880aae34f8edfd5e.zip
add compile_code function to compile before checking
Diffstat (limited to 'yaksh/python_stdout_evaluator.py')
-rw-r--r--yaksh/python_stdout_evaluator.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/yaksh/python_stdout_evaluator.py b/yaksh/python_stdout_evaluator.py
index 9443e37..85efa51 100644
--- a/yaksh/python_stdout_evaluator.py
+++ b/yaksh/python_stdout_evaluator.py
@@ -25,22 +25,31 @@ def redirect_stdout():
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:
+ g = {}
+ exec submitted in g
+ self.output_value = output_buffer.getvalue()
+ return self.output_value
+
def check_code(self, user_answer, expected_output):
success = False
tb = None
- # expected_output = test_case_data[0]
- submitted = compile(user_answer, '<string>', mode='exec')
- with redirect_stdout() as output_buffer:
- g = {}
- exec submitted in g
- raw_output_value = output_buffer.getvalue()
- # output_value = raw_output_value.encode('string_escape').strip()
- output_value = raw_output_value.strip()
+ # submitted = compile(user_answer, '<string>', mode='exec')
+ # with redirect_stdout() as output_buffer:
+ # g = {}
+ # exec submitted in g
+ # raw_output_value = output_buffer.getvalue()
+ # output_value = raw_output_value.strip()
if expected_output in user_answer:
success = False
err = "Incorrect Answer: Please avoid printing the expected output directly"
- elif output_value == expected_output:
+ elif self.output_value == expected_output:
success = True
err = "Correct answer"