Rev 5809: Add the subunit-sum script as-is. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Jun 16 10:38:51 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5809
revision-id: v.ladeuil+lp at free.fr-20110616103851-c6n748igl9ibz2ls
parent: v.ladeuil+lp at free.fr-20110616101054-c6ijva2wpnjh6ijy
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: selftest-config-stats
timestamp: Thu 2011-06-16 12:38:51 +0200
message:
Add the subunit-sum script as-is.
-------------- next part --------------
=== added file 'tools/subunit-sum'
--- a/tools/subunit-sum 1970-01-01 00:00:00 +0000
+++ b/tools/subunit-sum 2011-06-16 10:38:51 +0000
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+"""Displays the sum of a counter in a subunit stream."""
+
+from optparse import OptionParser
+import sys
+import testtools
+import unittest
+
+from subunit import DiscardStream, ProtocolTestCase
+
+class TestSumCounter(testtools.TestResult):
+
+ def __init__(self, counter_names):
+ """Create a FilterResult object outputting to stream."""
+ testtools.TestResult.__init__(self)
+ self.counter_names = counter_names
+ self.totals = {}
+ self.longest = 0
+ for name in counter_names:
+ l = len(name)
+ if l > self.longest: self.longest = l
+ self.totals[name] = 0
+
+ def addSuccess(self, test, details):
+ for name in self.counter_names:
+ try:
+ counter_text = ''.join(details[name].iter_text())
+ except KeyError, e:
+ # this counter doesn't exist for the test
+ continue
+ self.totals[name] += int(counter_text)
+
+ def display_totals(self, stream):
+ for name in self.counter_names:
+ stream.write('%-*s: %s\n'
+ % (self.longest, name, self.totals[name]))
+
+
+counter_names = sys.argv[1:]
+result = TestSumCounter(counter_names)
+test = ProtocolTestCase(sys.stdin)
+test.run(result)
+result.display_totals(sys.stdout)
More information about the bazaar-commits
mailing list