From 032d496c7fa7298a0748885b0f1c8e2c24af67d8 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 5 Apr 2018 15:30:01 +0530 Subject: Change error_messages.py, python_assertion_evaluator.py and grader.py - Pep8 changes - Show code error message along with test case - Add nose in python exec scope --- yaksh/error_messages.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'yaksh/error_messages.py') diff --git a/yaksh/error_messages.py b/yaksh/error_messages.py index 7ea8618..f2dc7c6 100644 --- a/yaksh/error_messages.py +++ b/yaksh/error_messages.py @@ -3,6 +3,7 @@ try: except ImportError: from itertools import izip_longest as zip_longest + def prettify_exceptions(exception, message, traceback=None, testcase=None): err = {"type": "assertion", "exception": exception, @@ -13,23 +14,27 @@ def prettify_exceptions(exception, message, traceback=None, testcase=None): err["traceback"] = None if exception == 'AssertionError': - value = ("Expected answer from the" - + " test case did not match the output") - err["message"] = value + value = ("Expected answer from the" + + " test case did not match the output") + if message: + err["message"] = message + else: + err["message"] = value err["traceback"] = None - if testcase: - err["test_case"] = testcase + err["test_case"] = testcase return err + def _get_incorrect_user_lines(exp_lines, user_lines): err_line_numbers = [] for line_no, (expected_line, user_line) in \ - enumerate(zip_longest(exp_lines, user_lines)): - if not user_line or not expected_line or \ - user_line.strip() != expected_line.strip(): + enumerate(zip_longest(exp_lines, user_lines)): + if (not user_line or not expected_line or + user_line.strip() != expected_line.strip()): err_line_numbers.append(line_no) return err_line_numbers - + + def compare_outputs(expected_output, user_output, given_input=None): given_lines = user_output.splitlines() exp_lines = expected_output.splitlines() @@ -44,18 +49,17 @@ def compare_outputs(expected_output, user_output, given_input=None): msg["error_line_numbers"] = err_line_numbers if ng != ne: msg["error_msg"] = ("Incorrect Answer: " - + "We had expected {} number of lines. "\ - .format(ne) + + "We had expected {} number of lines. ".format(ne) + "We got {} number of lines.".format(ng) ) return False, msg else: if err_line_numbers: msg["error_msg"] = ("Incorrect Answer: " - + "Line number(s) {0} did not match." - .format(", ".join(map( - str,[x+1 for x in err_line_numbers] - )))) + + "Line number(s) {0} did not match." + .format(", ".join( + map(str, [x+1 for x in err_line_numbers]) + ))) return False, msg else: msg["error_msg"] = "Correct Answer" -- cgit From 463cd907d0e744d5bbbd5ed5f0d0dde1bd8ca162 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 6 Apr 2018 15:01:01 +0530 Subject: Add error line number in error output --- yaksh/error_messages.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'yaksh/error_messages.py') 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 -- cgit From 97b657edc2a323f832c81f0e34ce5761bd21f7e9 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 24 May 2018 12:07:39 +0530 Subject: Pep8 changes --- yaksh/error_messages.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'yaksh/error_messages.py') diff --git a/yaksh/error_messages.py b/yaksh/error_messages.py index 7a18c22..512d664 100644 --- a/yaksh/error_messages.py +++ b/yaksh/error_messages.py @@ -50,15 +50,15 @@ def compare_outputs(expected_output, user_output, given_input=None): err_line_numbers = _get_incorrect_user_lines(exp_lines, given_lines) msg["error_line_numbers"] = err_line_numbers if ng != ne: - msg["error_msg"] = ("Incorrect Answer: " - + "We had expected {} number of lines. ".format(ne) - + "We got {} number of lines.".format(ng) + msg["error_msg"] = ("Incorrect Answer: " + + "We had expected {} number of lines. ".format(ne) + + "We got {} number of lines.".format(ng) ) return False, msg else: if err_line_numbers: - msg["error_msg"] = ("Incorrect Answer: " - + "Line number(s) {0} did not match." + msg["error_msg"] = ("Incorrect Answer: " + + "Line number(s) {0} did not match." .format(", ".join( map(str, [x+1 for x in err_line_numbers]) ))) -- cgit