diff options
author | ankitjavalkar | 2016-03-17 16:42:33 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:00:33 +0530 |
commit | 0520bf284f9b34782fa90b433d714c887049f339 (patch) | |
tree | ff1d81f59ea849740bd37ca70a11eaa821187fbc /yaksh/python_code_evaluator.py | |
parent | 195aead9b0fab0d8cdb86a9fc884ac3edca5db84 (diff) | |
download | online_test-0520bf284f9b34782fa90b433d714c887049f339.tar.gz online_test-0520bf284f9b34782fa90b433d714c887049f339.tar.bz2 online_test-0520bf284f9b34782fa90b433d714c887049f339.zip |
- Add test cases for multiple python evaluators
- Change name from python_standard_evaluator to python_assertion_evaluator
Diffstat (limited to 'yaksh/python_code_evaluator.py')
-rw-r--r-- | yaksh/python_code_evaluator.py | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/yaksh/python_code_evaluator.py b/yaksh/python_code_evaluator.py deleted file mode 100644 index a131a0e..0000000 --- a/yaksh/python_code_evaluator.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -import sys -import traceback -import os -from os.path import join -import importlib - -# local imports -from code_evaluator import CodeEvaluator, TimeoutException - - -class PythonCodeEvaluator(CodeEvaluator): - """Tests the Python code obtained from Code Server""" - - # def check_code(self, test, user_answer, ref_code_path): - def check_code(self, user_answer, test_cases): - success = False - - try: - tb = None - submitted = compile(user_answer, '<string>', mode='exec') - g = {} - exec submitted in g - for test_code in test_cases: - _tests = compile(test_code, '<string>', mode='exec') - exec _tests in g - except AssertionError: - type, value, tb = sys.exc_info() - info = traceback.extract_tb(tb) - fname, lineno, func, text = info[-1] - text = str(test_code).splitlines()[lineno-1] - err = "{0} {1} in: {2}".format(type.__name__, str(value), text) - except TimeoutException: - raise - except Exception: - err = traceback.format_exc(limit=0) - else: - success = True - err = 'Correct answer' - - del tb - return success, err - - # def unpack_test_case_data(self, test_case_data): - # test_cases = [] - # for t in test_case_data: - # test_case = t.get('test_case') - # test_cases.append(test_case) - - # return test_cases - - # def check_code(self): - # success = False - - # try: - # tb = None - # test_code = self._create_test_case() - # submitted = compile(self.user_answer, '<string>', mode='exec') - # g = {} - # exec submitted in g - # _tests = compile(test_code, '<string>', mode='exec') - # exec _tests in g - # except AssertionError: - # type, value, tb = sys.exc_info() - # info = traceback.extract_tb(tb) - # fname, lineno, func, text = info[-1] - # text = str(test_code).splitlines()[lineno-1] - # err = "{0} {1} in: {2}".format(type.__name__, str(value), text) - # else: - # success = True - # err = 'Correct answer' - - # del tb - # return success, err - - # def _create_test_case(self): - # """ - # Create assert based test cases in python - # """ - # test_code = "" - # if self.test: - # return self.test - # elif self.test_case_data: - # for test_case in self.test_case_data: - # pos_args = ", ".join(str(i) for i in test_case.get('pos_args')) \ - # if test_case.get('pos_args') else "" - # kw_args = ", ".join(str(k+"="+a) for k, a - # in test_case.get('kw_args').iteritems()) \ - # if test_case.get('kw_args') else "" - # args = pos_args + ", " + kw_args if pos_args and kw_args \ - # else pos_args or kw_args - # function_name = test_case.get('func_name') - # expected_answer = test_case.get('expected_answer') - - # tcode = "assert {0}({1}) == {2}".format(function_name, args, - # expected_answer) - # test_code += tcode + "\n" - # return test_code |