Package buildbot :: Package steps :: Module subunit
[frames] | no frames]

Source Code for Module buildbot.steps.subunit

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16   
 17  from buildbot.steps.shell import ShellCommand 
 18  from buildbot.status.results import SUCCESS, FAILURE 
 19   
20 -class SubunitShellCommand(ShellCommand):
21 """A ShellCommand that sniffs subunit output. 22 """ 23
24 - def __init__(self, failureOnNoTests=False, *args, **kwargs):
25 ShellCommand.__init__(self, *args, **kwargs) 26 self.failureOnNoTests = failureOnNoTests 27 # importing here gets around an import loop 28 from buildbot.process import subunitlogobserver 29 self.ioObverser = subunitlogobserver.SubunitLogObserver() 30 self.addLogObserver('stdio', self.ioObverser) 31 self.progressMetrics = self.progressMetrics + ('tests', 'tests failed')
32 - def commandComplete(self, cmd):
33 # figure out all statistics about the run 34 ob = self.ioObverser 35 failures = len(ob.failures) 36 errors = len(ob.errors) 37 skips = len(ob.skips) 38 total = ob.testsRun 39 40 count = failures + errors 41 42 text = [self.name] 43 text2 = "" 44 45 if not count: 46 results = SUCCESS 47 if total: 48 text += ["%d %s" % \ 49 (total, 50 total == 1 and "test" or "tests"), 51 "passed"] 52 elif self.failureOnNoTests: 53 results = FAILURE 54 text += ["no test is found"] 55 else: 56 text += ["no tests", "run"] 57 else: 58 results = FAILURE 59 text.append("Total %d test(s)" % total) 60 if failures: 61 text.append("%d %s" % \ 62 (failures, 63 failures == 1 and "failure" or "failures")) 64 if errors: 65 text.append("%d %s" % \ 66 (errors, 67 errors == 1 and "error" or "errors")) 68 text2 = "%d tes%s" % (count, (count == 1 and 't' or 'ts')) 69 70 71 if skips: 72 text.append("%d %s" % (skips, 73 skips == 1 and "skip" or "skips")) 74 75 #TODO: expectedFailures/unexpectedSuccesses 76 77 self.results = results 78 self.text = text 79 self.text2 = [text2]
80
81 - def evaluateCommand(self, cmd):
82 if cmd.rc != 0: 83 return FAILURE 84 return self.results
85
86 - def createSummary(self, loog):
87 ob = self.ioObverser 88 problems = "" 89 for test, err in ob.errors + ob.failures: 90 problems += "%s\n%s" % (test.id(), err) 91 if problems: 92 self.addCompleteLog("problems", problems) 93 warnings = ob.warningio.getvalue() 94 if warnings: 95 self.addCompleteLog("warnings", warnings)
96
97 - def getText(self, cmd, results):
98 return self.text
99 - def getText2(self, cmd, results):
100 return self.text2
101