diff options
author | ankitjavalkar | 2016-04-18 15:22:25 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:16:26 +0530 |
commit | 2c7f278382f4fe8071508b0a880aae34f8edfd5e (patch) | |
tree | 3268bd3b29bf7e0148ca818c25c128bd0d38a944 /yaksh/python_assertion_evaluator.py | |
parent | d3241512c71d61b355358a691d18e4ff8a8df34c (diff) | |
download | online_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_assertion_evaluator.py')
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 15ff8fd..c6661d1 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -12,17 +12,26 @@ from code_evaluator import CodeEvaluator, TimeoutException class PythonAssertionEvaluator(CodeEvaluator): """Tests the Python code obtained from Code Server""" + def compile_code(self, user_answer, test_case): + if hasattr(self, 'g'): + return None + else: + submitted = compile(user_answer, '<string>', mode='exec') + self.g = {} + exec submitted in self.g + return self.g + # def check_code(self, test, user_answer, ref_code_path): # def check_code(self, user_answer, test_case_data): #@@@v2 def check_code(self, user_answer, test_case): success = False try: tb = None - submitted = compile(user_answer, '<string>', mode='exec') - g = {} - exec submitted in g + # submitted = compile(user_answer, '<string>', mode='exec') + # g = {} + # exec submitted in g _tests = compile(test_case, '<string>', mode='exec') - exec _tests in g + exec _tests in self.g except AssertionError: type, value, tb = sys.exc_info() info = traceback.extract_tb(tb) |