OLD | NEW |
| (Empty) |
1 # -*- test-case-name: buildbot.test.test_buildstep -*- | |
2 | |
3 from unittest import TestResult | |
4 | |
5 from buildbot.steps.shell import ShellCommand | |
6 from buildbot.process import buildstep | |
7 | |
8 | |
9 class DiscardStream: | |
10 """A trivial thunk used to discard passthrough content.""" | |
11 | |
12 def write(self, bytes): | |
13 pass | |
14 | |
15 | |
16 class SubunitLogObserver(buildstep.LogLineObserver, TestResult): | |
17 """Observe a log that may contain subunit output. | |
18 | |
19 This class extends TestResult to receive the callbacks from the subunit | |
20 parser in the most direct fashion. | |
21 """ | |
22 | |
23 def __init__(self): | |
24 buildstep.LogLineObserver.__init__(self) | |
25 TestResult.__init__(self) | |
26 try: | |
27 from subunit import TestProtocolServer | |
28 except ImportError: | |
29 raise ImportError("subunit is not importable, but is required for " | |
30 "SubunitLogObserver support.") | |
31 self.protocol = TestProtocolServer(self, DiscardStream()) | |
32 | |
33 def outLineReceived(self, line): | |
34 """Process a received line.""" | |
35 # Impedance mismatch: subunit wants lines, observers get lines-no\n | |
36 self.protocol.lineReceived(line + '\n') | |
37 | |
38 def startTest(self, test): | |
39 TestResult.startTest(self, test) | |
40 self.step.setProgress('tests', self.testsRun) | |
41 | |
42 def addError(self, test, err): | |
43 TestResult.addError(self, test, err) | |
44 self.issue() | |
45 | |
46 def addFailure(self, test, err): | |
47 TestResult.addFailure(self, test, err) | |
48 self.issue() | |
49 | |
50 def issue(self): | |
51 """An issue - failing, erroring etc test.""" | |
52 self.step.setProgress('tests failed', len(self.failures) + len(self.erro
rs)) | |
53 | |
54 | |
55 class SubunitShellCommand(ShellCommand): | |
56 """A ShellCommand that sniffs subunit output. | |
57 | |
58 Ideally not needed, and thus here to be trivially deleted. See issue #615 | |
59 """ | |
60 | |
61 def __init__(self, *args, **kwargs): | |
62 ShellCommand.__init__(self, *args, **kwargs) | |
63 self.addLogObserver('stdio', SubunitLogObserver()) | |
64 self.progressMetrics = self.progressMetrics + ('tests', 'tests failed') | |
OLD | NEW |