summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-02-22 20:07:20 +0530
committerGitHub2017-02-22 20:07:20 +0530
commitb3a47d8d4b90b4540876d3dbd1aa0c9c334d84e8 (patch)
tree8362d45d91afc624b096fe042fa32b6670170f95 /yaksh
parentee83b9693075771dcba885bc380e20dfdd8289a1 (diff)
parentb3c1ea3bd82f03599393916138e19dc258e2e380 (diff)
downloadonline_test-b3a47d8d4b90b4540876d3dbd1aa0c9c334d84e8.tar.gz
online_test-b3a47d8d4b90b4540876d3dbd1aa0c9c334d84e8.tar.bz2
online_test-b3a47d8d4b90b4540876d3dbd1aa0c9c334d84e8.zip
Merge pull request #221 from ankitjavalkar/format-assert-error
Format the assertion and various error exceptions for Python Assertion evaluator
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/evaluator_tests/test_python_evaluation.py13
-rw-r--r--yaksh/python_assertion_evaluator.py27
2 files changed, 25 insertions, 15 deletions
diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py
index 6346941..51f9bea 100644
--- a/yaksh/evaluator_tests/test_python_evaluation.py
+++ b/yaksh/evaluator_tests/test_python_evaluation.py
@@ -235,7 +235,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
# Then
self.assertFalse(result.get("success"))
- self.assertEqual(6, len(err))
+ self.assertEqual(25, len(err))
for msg in name_error_msg:
self.assert_correct_output(msg, result.get("error"))
@@ -245,8 +245,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
def add(a, b):
return add(3, 3)
""")
- recursion_error_msg = ["Traceback",
- "call",
+ recursion_error_msg = ["Traceback",
"maximum recursion depth exceeded"
]
@@ -301,7 +300,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
# Then
self.assertFalse(result.get("success"))
- self.assertEqual(6, len(err))
+ self.assertEqual(25, len(err))
for msg in type_error_msg:
self.assert_correct_output(msg, result.get("error"))
@@ -337,7 +336,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
# Then
self.assertFalse(result.get("success"))
- self.assertEqual(6, len(err))
+ self.assertEqual(28, len(err))
for msg in value_error_msg:
self.assert_correct_output(msg, result.get("error"))
@@ -404,7 +403,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
# Then
self.assertFalse(result.get("success"))
- self.assertEqual(5, len(err))
+ self.assertEqual(13, len(err))
for msg in syntax_error_msg:
self.assert_correct_output(msg, result.get("error"))
@@ -446,7 +445,7 @@ class PythonAssertionEvaluationTestCases(EvaluatorBaseTest):
# Then
self.assertFalse(result.get("success"))
- self.assertEqual(2, len(err))
+ self.assertEqual(11, len(err))
for msg in name_error_msg:
self.assert_correct_output(msg, result.get("error"))
diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py
index 11fa101..c8f2dd0 100644
--- a/yaksh/python_assertion_evaluator.py
+++ b/yaksh/python_assertion_evaluator.py
@@ -2,6 +2,7 @@
import sys
import traceback
import os
+import re
from os.path import join
import importlib
@@ -70,23 +71,33 @@ 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)
+
+ # 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 - {1} {2} in:\n {3}\n".format(
+ "Error Traceback - {1} {2} in:\n {3}\n{4}".format(
self.test_case,
type.__name__,
str(value),
- text
+ text,
+ stripped_tb
)
- except TimeoutException:
- raise
- except Exception:
- msg = traceback.format_exc(limit=0)
- err = "Error in Test case: {0}".format(msg)
else:
success = True
err = None