diff options
author | adityacp | 2018-04-06 15:01:01 +0530 |
---|---|---|
committer | adityacp | 2018-04-06 15:01:01 +0530 |
commit | 463cd907d0e744d5bbbd5ed5f0d0dde1bd8ca162 (patch) | |
tree | f588d67b8e0390099f79d3d696bce80e8c2536a2 | |
parent | 680b741cb066bae3e074c9feade61bf7792ef384 (diff) | |
download | online_test-463cd907d0e744d5bbbd5ed5f0d0dde1bd8ca162.tar.gz online_test-463cd907d0e744d5bbbd5ed5f0d0dde1bd8ca162.tar.bz2 online_test-463cd907d0e744d5bbbd5ed5f0d0dde1bd8ca162.zip |
Add error line number in error output
-rw-r--r-- | yaksh/error_messages.py | 4 | ||||
-rw-r--r-- | yaksh/evaluator_tests/test_python_evaluation.py | 1 | ||||
-rw-r--r-- | yaksh/grader.py | 5 | ||||
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 4 |
4 files changed, 10 insertions, 4 deletions
diff --git a/yaksh/error_messages.py b/yaksh/error_messages.py index f2dc7c6..7a18c22 100644 --- a/yaksh/error_messages.py +++ b/yaksh/error_messages.py @@ -4,7 +4,8 @@ except ImportError: from itertools import izip_longest as zip_longest -def prettify_exceptions(exception, message, traceback=None, testcase=None): +def prettify_exceptions(exception, message, traceback=None, + testcase=None, line_no=None): err = {"type": "assertion", "exception": exception, "traceback": traceback, @@ -22,6 +23,7 @@ def prettify_exceptions(exception, message, traceback=None, testcase=None): err["message"] = value err["traceback"] = None err["test_case"] = testcase + err["line_no"] = line_no return err diff --git a/yaksh/evaluator_tests/test_python_evaluation.py b/yaksh/evaluator_tests/test_python_evaluation.py index 886ed01..2748d8a 100644 --- a/yaksh/evaluator_tests/test_python_evaluation.py +++ b/yaksh/evaluator_tests/test_python_evaluation.py @@ -934,5 +934,6 @@ class PythonHookEvaluationTestCases(EvaluatorBaseTest): # Then self.assertTrue(result.get('success')) + if __name__ == '__main__': unittest.main() diff --git a/yaksh/grader.py b/yaksh/grader.py index a721236..d81470b 100644 --- a/yaksh/grader.py +++ b/yaksh/grader.py @@ -148,14 +148,15 @@ class Grader(object): error.append( prettify_exceptions("TimeoutException", self.timeout_msg) ) - except Exception: + except Exception as e: exc_type, exc_value, exc_tb = sys.exc_info() tb_list = traceback.format_exception(exc_type, exc_value, exc_tb) + line_no = e.lineno if len(tb_list) > 2: del tb_list[1:3] error.append( prettify_exceptions( - exc_type.__name__, str(exc_value), "".join(tb_list) + exc_type.__name__, str(exc_value), "".join(tb_list), line_no=line_no ) ) finally: diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index 8c7d451..1f2b82b 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -74,12 +74,14 @@ class PythonAssertionEvaluator(BaseEvaluator): except Exception: exc_type, exc_value, exc_tb = sys.exc_info() tb_list = traceback.format_exception(exc_type, exc_value, exc_tb) + line_no = traceback.extract_tb(exc_tb)[-1][1] 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 + self.test_case, + line_no ) else: success = True |