waf: added top level build rules
[samba.git] / selftest / subunithelper.py
index e60c8d340c1739e7c4b5c0a172a0de449e0ad075..c59b6d002c39f3d736989df3124d6feeafba01b4 100644 (file)
@@ -32,6 +32,7 @@ class TestsuiteEnabledTestResult(testtools.testresult.TestResult):
 
 
 def parse_results(msg_ops, statistics, fh):
+    exitcode = 0
     expected_fail = 0
     open_tests = {}
 
@@ -95,6 +96,7 @@ def parse_results(msg_ops, statistics, fh):
                     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
@@ -104,6 +106,7 @@ def parse_results(msg_ops, statistics, fh):
                     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
@@ -114,9 +117,11 @@ def parse_results(msg_ops, statistics, fh):
                     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
@@ -128,6 +133,7 @@ def parse_results(msg_ops, statistics, fh):
                 msg_ops.addSkip(test, reason)
             elif result == "error":
                 statistics['TESTS_ERROR']+=1
+                exitcode = 1
                 try:
                     test = open_tests.pop(testname)
                 except KeyError:
@@ -139,10 +145,12 @@ def parse_results(msg_ops, statistics, fh):
                 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-error":
                 msg_ops.end_testsuite(testname, "error", reason)
+                exitcode = 1
             else:
                 raise AssertionError("Recognized but unhandled result %r" %
                     result)
@@ -165,12 +173,9 @@ def parse_results(msg_ops, statistics, fh):
         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
 
-    if statistics['TESTS_ERROR'] > 0:
-        return 1
-    if statistics['TESTS_UNEXPECTED_FAIL'] > 0:
-        return 1
-    return 0
+    return exitcode
 
 
 class SubunitOps(subunit.TestProtocolClient,TestsuiteEnabledTestResult):
@@ -247,6 +252,7 @@ class FilterOps(testtools.testresult.TestResult):
             self.output+=msg
 
     def startTest(self, test):
+        self.seen_output = True
         test = self._add_prefix(test)
         if self.strip_ok_output:
            self.output = ""
@@ -269,6 +275,7 @@ class FilterOps(testtools.testresult.TestResult):
             raise ImmediateFail()
 
     def addSkip(self, test, details=None):
+        self.seen_output = True
         test = self._add_prefix(test)
         self._ops.addSkip(test, details)
         self.output = None
@@ -341,6 +348,7 @@ class FilterOps(testtools.testresult.TestResult):
     def __init__(self, out, prefix=None, expected_failures=None,
                  strip_ok_output=False, fail_immediately=False):
         self._ops = out
+        self.seen_output = False
         self.output = None
         self.prefix = prefix
         if expected_failures is not None:
@@ -376,7 +384,7 @@ class PlainFormatter(TestsuiteEnabledTestResult):
         self.totalsuites = totaltests
         self.last_time = None
 
-    @classmethod
+    @staticmethod
     def _format_time(delta):
         minutes, seconds = divmod(delta.seconds, 60)
         hours, minutes = divmod(minutes, 60)
@@ -495,7 +503,7 @@ class PlainFormatter(TestsuiteEnabledTestResult):
 
         self.test_output[self.name] += "UNEXPECTED(%s): %s\n" % (result, testname)
         if reason is not None:
-            self.test_output[self.name] += "REASON: %s\n" % (reason[1].message.encode("utf-8").strip(),)
+            self.test_output[self.name] += "REASON: %s\n" % (unicode(reason[1]).encode("utf-8").strip(),)
 
         if self.immediate and not self.verbose:
             print self.test_output[self.name]
@@ -552,5 +560,3 @@ class PlainFormatter(TestsuiteEnabledTestResult):
         self.skips.setdefault(reason, []).append(name)
         if self.totalsuites:
             self.totalsuites-=1
-
-