diff options
author | maheshgudi | 2017-10-26 18:34:36 +0530 |
---|---|---|
committer | maheshgudi | 2017-11-07 14:50:09 +0530 |
commit | 16e8d4b3c096e6034c0066adffc8f5a520f272c7 (patch) | |
tree | af551bc18cb679bd816a78b45b8087beabf8a5be /yaksh/python_assertion_evaluator.py | |
parent | 807a52e45a9b6c6ac64a7a5e4bd8248900fb4367 (diff) | |
download | online_test-16e8d4b3c096e6034c0066adffc8f5a520f272c7.tar.gz online_test-16e8d4b3c096e6034c0066adffc8f5a520f272c7.tar.bz2 online_test-16e8d4b3c096e6034c0066adffc8f5a520f272c7.zip |
Beautiful error outputs
Diffstat (limited to 'yaksh/python_assertion_evaluator.py')
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index c8f2dd0..35a08ec 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -4,6 +4,7 @@ import traceback import os import re from os.path import join +from textwrap import dedent import importlib # Local imports @@ -73,31 +74,26 @@ class PythonAssertionEvaluator(BaseEvaluator): exec(_tests, self.exec_scope) except TimeoutException: raise + except AssertionError: + type, _, tb = sys.exc_info() + tb_info = traceback.extract_tb(tb) + filename, line, func, text = tb_info[-1] + value = "Expected answer from the test case didnt match the output" + err = {"type": "assertion", + "test_case": self.test_case, + "exception": type.__name__, + "message": value + } except Exception: type, value, tb = sys.exc_info() - info = traceback.extract_tb(tb) - fname, lineno, func, text = info[-1] - text = str(self.test_case) + tb_info = traceback.extract_tb(tb) + filename, line, func, text = tb_info[-1] + err = {"type": "assertion", + "test_case": self.test_case, + "exception": type.__name__, + "message": str(value) + } - # Get truncated traceback - err_tb_lines = traceback.format_exc().splitlines() - stripped_tb_lines = [] - for line in err_tb_lines: - line = re.sub(r'File\s+".*?",\s+line', - 'File <file>, line', - line - ) - stripped_tb_lines.append(line) - stripped_tb = '\n'.join(stripped_tb_lines[-10::]) - - err = "Expected Test Case:\n{0}\n" \ - "Error Traceback - {1} {2} in:\n {3}\n{4}".format( - self.test_case, - type.__name__, - str(value), - text, - stripped_tb - ) else: success = True err = None |