def parse_results(msg_ops, statistics, fh): exitcode = 0 open_tests = {} while fh: l = fh.readline() if l == "": break parts = l.split(None, 1) if not len(parts) == 2 or not l.startswith(parts[0]): msg_ops.output_msg(l) continue command = parts[0].rstrip(":") arg = parts[1] if command in ("test", "testing"): msg_ops.control_msg(l) name = arg.rstrip() test = subunit.RemotedTestCase(name) if name in open_tests: msg_ops.addError(open_tests.pop(name), subunit.RemoteError(u"Test already running")) msg_ops.startTest(test) open_tests[name] = test elif command == "time": msg_ops.control_msg(l) try: dt = iso8601.parse_date(arg.rstrip("\n")) except TypeError as e: print "Unable to parse time line: %s" % arg.rstrip("\n") else: msg_ops.time(dt) elif command in VALID_RESULTS: msg_ops.control_msg(l) result = command grp = re.match("(.*?)( \[)?([ \t]*)( multipart)?\n", arg) (testname, hasreason) = (grp.group(1), grp.group(2)) if hasreason: reason = "" # reason may be specified in next lines terminated = False while fh: l = fh.readline() if l == "": break msg_ops.control_msg(l) if l == "]\n": terminated = True break else: reason += l remote_error = subunit.RemoteError(reason.decode("utf-8")) if not terminated: statistics['TESTS_ERROR']+=1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"reason (%s) interrupted" % result)) return 1 else: reason = None remote_error = subunit.RemoteError(u"No reason specified") if result in ("success", "successful"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_EXPECTED_OK']+=1 msg_ops.addSuccess(test) elif result in ("xfail", "knownfail"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_EXPECTED_FAIL']+=1 msg_ops.addExpectedFailure(test, remote_error) elif result in ("uxsuccess", ): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_UNEXPECTED_OK']+=1 msg_ops.addUnexpectedSuccess(test) exitcode = 1 elif result in ("failure", "fail"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_UNEXPECTED_FAIL']+=1 exitcode = 1 msg_ops.addFailure(test, remote_error) elif result == "skip": statistics['TESTS_SKIP']+=1 # Allow tests to be skipped without prior announcement of test try: test = open_tests.pop(testname) except KeyError: test = subunit.RemotedTestCase(testname) msg_ops.addSkip(test, reason) elif result == "error": statistics['TESTS_ERROR']+=1 exitcode = 1 try: test = open_tests.pop(testname) except KeyError: test = subunit.RemotedTestCase(testname) msg_ops.addError(test, remote_error) elif result == "skip-testsuite": msg_ops.skip_testsuite(testname) elif result == "testsuite-success": msg_ops.end_testsuite(testname, "success", reason) elif result == "testsuite-failure": msg_ops.end_testsuite(testname, "failure", reason) exitcode = 1 elif result == "testsuite-xfail": msg_ops.end_testsuite(testname, "xfail", reason) elif result == "testsuite-uxsuccess": msg_ops.end_testsuite(testname, "uxsuccess", reason) exitcode = 1 elif result == "testsuite-error": msg_ops.end_testsuite(testname, "error", reason) exitcode = 1 else: raise AssertionError("Recognized but unhandled result %r" % result) elif command == "testsuite": msg_ops.start_testsuite(arg.strip()) elif command == "progress": arg = arg.strip() if arg == "pop": msg_ops.progress(None, subunit.PROGRESS_POP) elif arg == "push": msg_ops.progress(None, subunit.PROGRESS_PUSH) elif arg[0] in '+-': msg_ops.progress(int(arg), subunit.PROGRESS_CUR) else: msg_ops.progress(int(arg), subunit.PROGRESS_SET) else: msg_ops.output_msg(l) while open_tests: test = subunit.RemotedTestCase(open_tests.popitem()[1]) msg_ops.addError(test, subunit.RemoteError(u"was started but never finished!")) statistics['TESTS_ERROR']+=1 exitcode = 1 return exitcode
def parse_results(msg_ops, statistics, fh): exitcode = 0 open_tests = {} while fh: l = fh.readline() if l == "": break parts = l.split(None, 1) if not len(parts) == 2 or not l.startswith(parts[0]): msg_ops.output_msg(l) continue command = parts[0].rstrip(":") arg = parts[1] if command in ("test", "testing"): msg_ops.control_msg(l) name = arg.rstrip() test = subunit.RemotedTestCase(name) if name in open_tests: msg_ops.addError(open_tests.pop(name), subunit.RemoteError(u"Test already running")) msg_ops.startTest(test) open_tests[name] = test elif command == "time": msg_ops.control_msg(l) try: dt = iso8601.parse_date(arg.rstrip("\n")) except TypeError, e: print "Unable to parse time line: %s" % arg.rstrip("\n") else: msg_ops.time(dt) elif command in VALID_RESULTS: msg_ops.control_msg(l) result = command grp = re.match("(.*?)( \[)?([ \t]*)( multipart)?\n", arg) (testname, hasreason) = (grp.group(1), grp.group(2)) if hasreason: reason = "" # reason may be specified in next lines terminated = False while fh: l = fh.readline() if l == "": break msg_ops.control_msg(l) if l == "]\n": terminated = True break else: reason += l remote_error = subunit.RemoteError(reason.decode("utf-8")) if not terminated: statistics['TESTS_ERROR']+=1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"reason (%s) interrupted" % result)) return 1 else: reason = None remote_error = subunit.RemoteError(u"No reason specified") if result in ("success", "successful"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_EXPECTED_OK']+=1 msg_ops.addSuccess(test) elif result in ("xfail", "knownfail"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_EXPECTED_FAIL']+=1 msg_ops.addExpectedFailure(test, remote_error) elif result in ("uxsuccess", ): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_UNEXPECTED_OK']+=1 msg_ops.addUnexpectedSuccess(test) exitcode = 1 elif result in ("failure", "fail"): try: test = open_tests.pop(testname) except KeyError: statistics['TESTS_ERROR']+=1 exitcode = 1 msg_ops.addError(subunit.RemotedTestCase(testname), subunit.RemoteError(u"Test was never started")) else: statistics['TESTS_UNEXPECTED_FAIL']+=1 exitcode = 1 msg_ops.addFailure(test, remote_error) elif result == "skip": statistics['TESTS_SKIP']+=1 # Allow tests to be skipped without prior announcement of test try: test = open_tests.pop(testname) except KeyError: test = subunit.RemotedTestCase(testname) msg_ops.addSkip(test, reason) elif result == "error": statistics['TESTS_ERROR']+=1 exitcode = 1 try: test = open_tests.pop(testname) except KeyError: test = subunit.RemotedTestCase(testname) msg_ops.addError(test, remote_error) elif result == "skip-testsuite": msg_ops.skip_testsuite(testname) elif result == "testsuite-success": msg_ops.end_testsuite(testname, "success", reason) elif result == "testsuite-failure": msg_ops.end_testsuite(testname, "failure", reason) exitcode = 1 elif result == "testsuite-xfail": msg_ops.end_testsuite(testname, "xfail", reason) elif result == "testsuite-uxsuccess": msg_ops.end_testsuite(testname, "uxsuccess", reason) exitcode = 1 elif result == "testsuite-error": msg_ops.end_testsuite(testname, "error", reason) exitcode = 1 else: raise AssertionError("Recognized but unhandled result %r" % result)