summaryrefslogtreecommitdiff
path: root/yaksh/python_assertion_evaluator.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-11-10 17:50:48 +0530
committerGitHub2017-11-10 17:50:48 +0530
commit96f8e0af5b39338741c758de918e32e02b95f0c8 (patch)
tree80fb17501e7995ed3abb34ac3b0d62dd8decc560 /yaksh/python_assertion_evaluator.py
parentcfcb2ed39c724639fe17338e29e327d08ae641b2 (diff)
parent95f862caee8ca6077ee8f9a8fc88d9ca44db1cdf (diff)
downloadonline_test-96f8e0af5b39338741c758de918e32e02b95f0c8.tar.gz
online_test-96f8e0af5b39338741c758de918e32e02b95f0c8.tar.bz2
online_test-96f8e0af5b39338741c758de918e32e02b95f0c8.zip
Merge pull request #380 from maheshgudi/beautify_assertions
Prettify assertion error output
Diffstat (limited to 'yaksh/python_assertion_evaluator.py')
-rw-r--r--yaksh/python_assertion_evaluator.py36
1 files changed, 10 insertions, 26 deletions
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py
index c8f2dd0..440f422 100644
--- a/yaksh/python_assertion_evaluator.py
+++ b/yaksh/python_assertion_evaluator.py
@@ -10,6 +10,7 @@ import importlib
from .file_utils import copy_files, delete_files
from .base_evaluator import BaseEvaluator
from .grader import TimeoutException
+from .error_messages import prettify_exceptions
class PythonAssertionEvaluator(BaseEvaluator):
@@ -68,39 +69,22 @@ class PythonAssertionEvaluator(BaseEvaluator):
success = False
mark_fraction = 0.0
try:
- tb = None
_tests = compile(self.test_case, '<string>', mode='exec')
exec(_tests, self.exec_scope)
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)
-
- # 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
- )
+ exc_type, exc_value, exc_tb = sys.exc_info()
+ tb_list = traceback.format_exception(exc_type, exc_value, exc_tb)
+ if len(tb_list) > 2:
+ del tb_list[1:3]
+ err = prettify_exceptions(exc_type.__name__,
+ str(exc_value),
+ "".join(tb_list),
+ self.test_case
+ )
else:
success = True
err = None
mark_fraction = 1.0 if self.partial_grading else 0.0
- del tb
return success, err, mark_fraction