diff options
author | mahesh | 2017-05-17 18:51:58 +0530 |
---|---|---|
committer | mahesh | 2017-05-17 18:51:58 +0530 |
commit | b591928d868ecf92660e43be72348334073ed502 (patch) | |
tree | 1826313f9a0c9cb78482a7ad45b0b5a6f785a164 | |
parent | 6c4ab452538fd23d67c1c2d508cb4768e601d688 (diff) | |
download | online_test-b591928d868ecf92660e43be72348334073ed502.tar.gz online_test-b591928d868ecf92660e43be72348334073ed502.tar.bz2 online_test-b591928d868ecf92660e43be72348334073ed502.zip |
adds pep8 changes
-rw-r--r-- | yaksh/compare_stdio.py | 76 | ||||
-rw-r--r-- | yaksh/templatetags/custom_filters.py | 2 |
2 files changed, 40 insertions, 38 deletions
diff --git a/yaksh/compare_stdio.py b/yaksh/compare_stdio.py index 3b1b998..c9c631f 100644 --- a/yaksh/compare_stdio.py +++ b/yaksh/compare_stdio.py @@ -4,40 +4,42 @@ except ImportError: from itertools import izip_longest as zip_longest class CompareOutputs(object): - - def _incorrect_user_lines(self, exp_lines, user_lines): - err_line_no = [] - for i, (expected_line, user_line) in enumerate(zip_longest(exp_lines, user_lines)): - if not user_line or not expected_line: - err_line_no.append(i) - else: - if user_line.strip() != expected_line.strip(): - err_line_no.append(i) - return err_line_no - - def compare_outputs(self, expected_output, user_output,given_input=None): - given_lines = user_output.splitlines() - exp_lines = expected_output.splitlines() - # if given_input: - # given_input = given_input.splitlines() - msg = {"given_input":given_input, - "expected_output": exp_lines, - "user_output":given_lines - } - ng = len(given_lines) - ne = len(exp_lines) - if ng != ne: - err_line_no = self._incorrect_user_lines(exp_lines, given_lines) - msg["error_no"] = err_line_no - msg["error"] = "Incorrect Answer: We had expected {0} number of lines. We got {1} number of lines.".format(ne, ng) - return False, msg - else: - err_line_no = self._incorrect_user_lines(exp_lines, given_lines) - if err_line_no: - msg["error_no"] = err_line_no - msg["error"] = "Incorrect Answer: Line number(s) {0} did not match."\ - .format(", ".join(map(str,[x+1 for x in err_line_no]))) - return False, msg - else: - msg["error"] = "Correct answer" - return True, msg + + def _incorrect_user_lines(self, exp_lines, user_lines): + err_line_no = [] + for i, (expected_line, user_line) in \ + enumerate(zip_longest(exp_lines, user_lines)): + if not user_line or not expected_line: + err_line_no.append(i) + else: + if user_line.strip() != expected_line.strip(): + err_line_no.append(i) + return err_line_no + + def compare_outputs(self, expected_output, user_output,given_input=None): + given_lines = user_output.splitlines() + exp_lines = expected_output.splitlines() + msg = {"given_input":given_input, + "expected_output": exp_lines, + "user_output":given_lines + } + ng = len(given_lines) + ne = len(exp_lines) + if ng != ne: + err_line_no = self._incorrect_user_lines(exp_lines, given_lines) + msg["error_no"] = err_line_no + msg["error"] = "Incorrect Answer: \ + We had expected {0} number of lines. \ + We got {1} number of lines. ".format(ne, ng) + return False, msg + else: + err_line_no = self._incorrect_user_lines(exp_lines, given_lines) + if err_line_no: + msg["error_no"] = err_line_no + msg["error"] = "Incorrect Answer: "\ + "Line number(s) {0} did not match."\ + .format(", ".join(map(str,[x+1 for x in err_line_no]))) + return False, msg + else: + msg["error"] = "Correct answer" + return True, msg diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py index 35ae795..693dc2b 100644 --- a/yaksh/templatetags/custom_filters.py +++ b/yaksh/templatetags/custom_filters.py @@ -23,4 +23,4 @@ def inprogress(answerpaper): @register.filter(name='zip') def zip_longest_out(a, b): - return zip_longest(a, b)
\ No newline at end of file + return zip_longest(a, b) |