Package buildbot :: Package process :: Module subunitlogobserver
[frames] | no frames]

Source Code for Module buildbot.process.subunitlogobserver

  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 unittest import TestResult 
 18  from StringIO import StringIO 
 19   
 20  from buildbot.process import buildstep 
 21  from buildbot.status.testresult import TestResult as aTestResult 
 22  from buildbot.status.results import SUCCESS, FAILURE, SKIPPED 
 23   
24 -class SubunitLogObserver(buildstep.LogLineObserver, TestResult):
25 """Observe a log that may contain subunit output. 26 27 This class extends TestResult to receive the callbacks from the subunit 28 parser in the most direct fashion. 29 """ 30
31 - def __init__(self):
32 buildstep.LogLineObserver.__init__(self) 33 TestResult.__init__(self) 34 try: 35 from subunit import TestProtocolServer, PROGRESS_CUR, PROGRESS_SET 36 from subunit import PROGRESS_PUSH, PROGRESS_POP 37 except ImportError: 38 raise ImportError("subunit is not importable, but is required for " 39 "SubunitLogObserver support.") 40 self.PROGRESS_CUR = PROGRESS_CUR 41 self.PROGRESS_SET = PROGRESS_SET 42 self.PROGRESS_PUSH = PROGRESS_PUSH 43 self.PROGRESS_POP = PROGRESS_POP 44 self.warningio = StringIO() 45 self.protocol = TestProtocolServer(self, self.warningio) 46 self.skips = [] 47 self.seen_tags = set() #don't yet know what tags does in subunit
48
49 - def outLineReceived(self, line):
50 """Process a received stdout line.""" 51 # Impedance mismatch: subunit wants lines, observers get lines-no\n 52 self.protocol.lineReceived(line + '\n')
53
54 - def errLineReceived(self, line):
55 """same for stderr line.""" 56 self.protocol.lineReceived(line + '\n')
57
58 - def stopTest(self, test):
59 TestResult.stopTest(self, test) 60 self.step.setProgress('tests', self.testsRun)
61
62 - def addSuccess(self, test):
63 TestResult.addSuccess(self, test) 64 self.addAResult(test, SUCCESS, 'SUCCESS')
65
66 - def addSkip(self, test, detail):
67 if hasattr(TestResult,'addSkip'): 68 TestResult.addSkip(self, test, detail) 69 else: 70 self.skips.append((test, detail)) 71 self.addAResult(test, SKIPPED, 'SKIPPED', detail)
72
73 - def addError(self, test, err):
74 TestResult.addError(self, test, err) 75 self.issue(test, err)
76
77 - def addFailure(self, test, err):
78 TestResult.addFailure(self, test, err) 79 self.issue(test, err)
80
81 - def addAResult(self, test, result, text, log=""):
82 tr = aTestResult(tuple(test.id().split('.')), result, text, log) 83 self.step.build.build_status.addTestResult(tr)
84
85 - def issue(self, test, err):
86 """An issue - failing, erroring etc test.""" 87 self.addAResult(test, FAILURE, 'FAILURE', err) 88 self.step.setProgress('tests failed', len(self.failures) + 89 len(self.errors))
90 91 expectedTests = 0 92 contextLevel = 0
93 - def progress(self, offset, whence):
94 if not self.contextLevel: 95 if whence == self.PROGRESS_CUR: 96 self.expectedTests += offset 97 elif whence == self.PROGRESS_SET: 98 self.expectedTests = offset 99 self.step.progress.setExpectations({'tests': self.expectedTests}) 100 #TODO: properly support PUSH/POP 101 if whence == self.PROGRESS_PUSH: 102 self.contextLevel += 1 103 elif whence == self.PROGRESS_POP: 104 self.contextLevel -= 1
105
106 - def tags(self, new_tags, gone_tags):
107 """Accumulate the seen tags.""" 108 self.seen_tags.update(new_tags)
109 110 # this used to be referenced here, so we keep a link for old time's sake 111 import buildbot.steps.subunit 112 SubunitShellCommand = buildbot.steps.subunit.SubunitShellCommand 113