diff options
author | ankitjavalkar | 2017-02-13 15:21:34 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-02-16 18:09:37 +0530 |
commit | 85412e8f77a268590cf8ca6f6cd6facd8fdc3c2c (patch) | |
tree | b552d367d054c7d13f928235a8ae7bdd8c8b8355 /yaksh/python_assertion_evaluator.py | |
parent | 8eea8e99258f073374912985acc191295536deeb (diff) | |
download | online_test-85412e8f77a268590cf8ca6f6cd6facd8fdc3c2c.tar.gz online_test-85412e8f77a268590cf8ca6f6cd6facd8fdc3c2c.tar.bz2 online_test-85412e8f77a268590cf8ca6f6cd6facd8fdc3c2c.zip |
Merge all error handling into single code block and fix relevant test cases for Python assertion
Diffstat (limited to 'yaksh/python_assertion_evaluator.py')
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 9e1a6ac..77efbc1 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -71,31 +71,30 @@ class PythonAssertionEvaluator(BaseEvaluator): tb = None _tests = compile(self.test_case, '<string>', mode='exec') exec(_tests, self.exec_scope) - except AssertionError: + except TimeoutException: + raise + except Exception: type, value, tb = sys.exc_info() info = traceback.extract_tb(tb) fname, lineno, func, text = info[-1] text = str(self.test_case) - err = "Expected Test Case:\n{0}\n" \ - "Error - {1} {2} in:\n {3}\n".format( - self.test_case, - type.__name__, - str(value), - text - ) - except TimeoutException: - raise - except RecursionError: - msg = traceback.format_exc(limit=0) - err = "Error Traceback: {0}".format(msg) - except Exception: + + # Get truncated traceback err_tb_lines = traceback.format_exc().splitlines() stripped_tb_lines = [] for line in err_tb_lines: if '.py' not in line: stripped_tb_lines.append(line) - stripped_tb = '\n'.join(stripped_tb_lines) - err = "Error Traceback:\n{0}".format(stripped_tb) + 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 |