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 self.addFactoryArguments(failureOnNoTests=failureOnNoTests) 28 29 # importing here gets around an import loop 30 from buildbot.process import subunitlogobserver 31 32 self.ioObverser = subunitlogobserver.SubunitLogObserver() 33 self.addLogObserver('stdio', self.ioObverser) 34 self.progressMetrics = self.progressMetrics + ('tests', 'tests failed')
35
36 - def commandComplete(self, cmd):
37 # figure out all statistics about the run 38 ob = self.ioObverser 39 failures = len(ob.failures) 40 errors = len(ob.errors) 41 skips = len(ob.skips) 42 total = ob.testsRun 43 44 count = failures + errors 45 46 text = [self.name] 47 text2 = "" 48 49 if not count: 50 results = SUCCESS 51 if total: 52 text += ["%d %s" % \ 53 (total, 54 total == 1 and "test" or "tests"), 55 "passed"] 56 else: 57 if self.failureOnNoTests: 58 results = FAILURE 59 text += ["no tests", "run"] 60 else: 61 results = FAILURE 62 text.append("Total %d test(s)" % total) 63 if failures: 64 text.append("%d %s" % \ 65 (failures, 66 failures == 1 and "failure" or "failures")) 67 if errors: 68 text.append("%d %s" % \ 69 (errors, 70 errors == 1 and "error" or "errors")) 71 text2 = "%d %s" % (count, (count == 1 and 'test' or 'tests')) 72 73 74 if skips: 75 text.append("%d %s" % (skips, 76 skips == 1 and "skip" or "skips")) 77 78 #TODO: expectedFailures/unexpectedSuccesses 79 80 self.results = results 81 self.text = text 82 self.text2 = [text2]
83
84 - def evaluateCommand(self, cmd):
85 if cmd.rc != 0: 86 return FAILURE 87 return self.results
88
89 - def createSummary(self, loog):
90 ob = self.ioObverser 91 problems = "" 92 for test, err in ob.errors + ob.failures: 93 problems += "%s\n%s" % (test.id(), err) 94 if problems: 95 self.addCompleteLog("problems", problems) 96 warnings = ob.warningio.getvalue() 97 if warnings: 98 self.addCompleteLog("warnings", warnings)
99
100 - def getText(self, cmd, results):
101 return self.text
102 - def getText2(self, cmd, results):
103 return self.text2
104