smbXcli: split out a smb1cli_req_flags() function
[gd/samba-autobuild/.git] / selftest / format-subunit
index 6d2ceb10478cf623df727bcb74a2b930e82db19a..b927e95ae483fd231966b76d4457291781df288b 100755 (executable)
@@ -8,175 +8,11 @@ import optparse
 import os
 import signal
 import sys
-import subunithelper
-import subunit
-
-class PlainFormatter(object):
-
-    def __init__(self, summaryfile, verbose, immediate, statistics,
-            totaltests=None):
-        self.verbose = verbose
-        self.immediate = immediate
-        self.statistics = statistics
-        self.start_time = None
-        self.test_output = {}
-        self.suitesfailed = []
-        self.suites_ok = 0
-        self.skips = {}
-        self.summaryfile = summaryfile
-        self.index = 0
-        self.name = None
-        self._progress_level = 0
-        self.totalsuites = totaltests
-
-    def progress(self, offset, whence):
-        if whence == subunit.PROGRESS_POP:
-            self._progress_level -= 1
-        elif whence == subunit.PROGRESS_PUSH:
-            self._progress_level += 1
-        elif whence == subunit.PROGRESS_SET:
-            if self._progress_level == 0:
-                self.totalsuites = offset
-        elif whence == subunit.PROGRESS_CUR:
-            raise NotImplementedError
-
-    def report_time(self, time):
-        if self.start_time is None:
-            self.start_time = time
-        self.last_time = time
-
-    def start_testsuite(self, name):
-        self.index += 1
-        self.name = name
-        testsuite_start_time = self.last_time
-
-        duration = testsuite_start_time - self.start_time
-
-        if not self.verbose:
-            self.test_output[name] = "" 
-
-        out = "[%d" % self.index
-        if self.totalsuites is not None:
-            out += "/%d" % self.totalsuites
-        out += " in %ds" % duration
-        if self.suitesfailed:
-            out += ", %d errors" % (len(self.suitesfailed),)
-        out += "] %s" % name 
-        if self.immediate:
-            sys.stdout.write(out + "\n")
-        else:
-            sys.stdout.write(out + ": ")
-
-    def output_msg(self, output):
-        if self.verbose:
-            sys.stdout.write(output)
-        elif self.name is not None:
-            self.test_output[self.name] += output
-        else:
-            sys.stdout.write(output)
-
-    def control_msg(self, output):
-        #$self->output_msg($output)
-        pass
-
-    def end_testsuite(self, name, result, reason):
-        out = ""
-        unexpected = 0
-
-        if not name in self.test_output:
-            print "no output for name[%s]" % name
-
-        if result in ("success", "xfail"):
-            self.suites_ok+=1
-        else:
-            self.output_msg("ERROR: Testsuite[%s]\nREASON: %s\n" % (name, reason or ''))
-            self.suitesfailed.append(name)
-            if self.immediate and not self.verbose:
-                out += self.test_output[name]
-            unexpected = 1
-
-        if not self.immediate:
-            if not unexpected:
-                out += " ok\n"
-            else:
-                out += " " + result.upper() + "\n"
-
-        sys.stdout.write(out)
-
-    def start_test(self, testname):
-        pass
-
-    def end_test(self, testname, result, unexpected, reason):
-        if not unexpected:
-            self.test_output[self.name] = ""
-            if not self.immediate:
-                sys.stdout.write({
-                    'failure': 'f',
-                    'xfail': 'X',
-                    'skip': 's',
-                    'success': '.'}.get(result, "?(%s)" % result))
-            return
-
-        if reason is None:
-            reason = ''
-        reason = reason.strip()
-
-        self.test_output[self.name] += "UNEXPECTED(%s): %s\nREASON: %s\n" % (result, testname, reason)
 
-        if self.immediate and not self.verbose:
-            print self.test_output[self.name]
-            self.test_output[self.name] = ""
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/subunit/python"))
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../lib/testtools"))
 
-        if not self.immediate:
-            sys.stdout.write({
-               'error': 'E',
-               'failure': 'F',
-               'success': 'S'}.get(result, "?"))
-
-    def summary(self):
-        f = open(self.summaryfile, 'w+')
-
-        if self.suitesfailed:
-            f.write("= Failed tests =\n")
-
-            for suite in self.suitesfailed:
-                f.write("== %s ==\n" % suite)
-                f.write(self.test_output[suite]+"\n\n")
-
-            f.write("\n")
-
-        if not self.immediate and not self.verbose:
-            for suite in self.suitesfailed:
-                print "=" * 78
-                print "FAIL: %s" % suite
-                print self.test_output[suite]
-                print ""
-
-        f.write("= Skipped tests =\n")
-        for reason in self.skips.keys():
-            f.write(reason + "\n")
-            for name in self.skips[reason]:
-                f.write("\t%s\n" % name)
-            f.write("\n")
-        f.close()
-
-        print "\nA summary with detailed information can be found in:"
-        print "  %s" % self.summaryfile
-
-        if not self.suitesfailed:
-            ok = (self.statistics['TESTS_EXPECTED_OK'] +
-                  self.statistics['TESTS_EXPECTED_FAIL'])
-            print "\nALL OK (%d tests in %d testsuites)" % (ok, self.suites_ok)
-        else:
-            print "\nFAILED (%d failures and %d errors in %d testsuites)" % (
-                self.statistics['TESTS_UNEXPECTED_FAIL'],
-                self.statistics['TESTS_ERROR'],
-                len(self.suitesfailed))
-
-    def skip_testsuite(self, name, reason="UNKNOWN"):
-        self.skips.setdefault(reason, []).append(name)
-        if self.totalsuites:
-            self.totalsuites-=1
+import subunithelper
 
 parser = optparse.OptionParser("format-subunit [options]")
 parser.add_option("--verbose", action="store_true",
@@ -188,6 +24,10 @@ parser.add_option("--prefix", type="string", default=".",
 
 opts, args = parser.parse_args()
 
+def handle_sigint(sig, stack):
+       sys.exit(0)
+signal.signal(signal.SIGINT, handle_sigint)
+
 statistics = {
     'SUITES_FAIL': 0,
     'TESTS_UNEXPECTED_OK': 0,
@@ -198,15 +38,15 @@ statistics = {
     'TESTS_SKIP': 0,
 }
 
-def handle_sigint(sig, stack):
-       sys.exit(0)
-signal.signal(signal.SIGINT, handle_sigint)
-
-msg_ops = PlainFormatter(os.path.join(opts.prefix, "summary"), opts.verbose,
-    opts.immediate, statistics)
+msg_ops = subunithelper.PlainFormatter(opts.verbose, opts.immediate, statistics)
 
 expected_ret = subunithelper.parse_results(msg_ops, statistics, sys.stdin)
 
-msg_ops.summary()
+summaryfile = os.path.join(opts.prefix, "summary")
+
+msg_ops.write_summary(summaryfile)
+
+print "\nA summary with detailed information can be found in:"
+print "  %s" % summaryfile
 
 sys.exit(expected_ret)