~frankban/+junk/lpbuildbot-lpsetup

« back to all changes in this revision

Viewing changes to bzrbuildbot/test.py

  • Committer: Benji York
  • Date: 2012-04-09 12:41:37 UTC
  • mfrom: (20.1.2 lpbuildbot-subunit)
  • Revision ID: benji.york@canonical.com-20120409124137-35newtn7yva60mld
[r=bac] make lpbuildbot understand subunit-style test results

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import re
2
 
 
3
 
import twisted.python.log
4
 
 
5
1
import buildbot.process.buildstep
6
2
import buildbot.steps.shell
7
3
 
8
 
 
9
 
class TestObserver(buildbot.process.buildstep.LogLineObserver):
10
 
    # adds a summary log, and keeps track of test count as we go.
11
 
 
12
 
    _ignore_line = re.compile(
13
 
        r'( [\w\.\/\-]+( ?\([\w\.\/\-]+\))?|'
14
 
        r'\s*Running.*|'
15
 
        r'\d{4}\-\d{2}\-\d{2} \d{2}\:\d{2}\:\d{2} INFO.+|'
16
 
        r'\s*Set up .+|'
17
 
        r'\s*Tear down .*|'
18
 
        r'  Ran \d+ tests with .+)$').match
19
 
 
20
 
    #  Ran 223 tests with 0 failures and 0 errors in 3 minutes 0.483 seconds.
21
 
    _intermediate_summary = re.compile(
22
 
        r'  Ran (\d+) tests? with (\d+) failures? and (\d+) errors? '
23
 
        r'in .*?[\d\.]+ seconds?.').match
24
 
 
25
 
    #Total: 20302 tests, 0 failures, 0 errors in 141 minutes 5.392 seconds.
26
 
    _final_summary = re.compile(
27
 
        r'Total: (\d+) tests?, (\d+) failures?, (\d+) errors? '
28
 
        r'in .*?[\d\.]+ seconds?.').match
29
 
 
30
 
    test_count = 0
31
 
    failure_count = 0
32
 
    error_count = 0
33
 
 
34
 
    finished = False
35
 
    log = None
36
 
 
37
 
    def outLineReceived(self, line):
38
 
        if self.finished:
39
 
            return
40
 
        if self.log is None:
41
 
            self.log = self.step.addLog('summary')
42
 
        report = False
43
 
        match = self._intermediate_summary(line)
44
 
        if match:
45
 
            total, failures, errors = match.groups()
46
 
            self.test_count += int(total)
47
 
            self.failure_count += int(failures)
48
 
            self.error_count += int(errors)
49
 
        else:
50
 
            match = self._final_summary(line)
51
 
            if match:
52
 
                self.finished = True
53
 
                total, failures, errors = match.groups()
54
 
                self.test_count = int(total)
55
 
                self.failure_count = int(failures)
56
 
                self.error_count = int(errors)
57
 
                report = True
58
 
            else:
59
 
                report = not self._ignore_line(line)
60
 
        if report:
61
 
            self.log.addStdout(line + '\n')
62
 
        if match:
63
 
            twisted.python.log.msg(
64
 
                '%d tests, %d failures, %d errors' %
65
 
                (self.test_count, self.failure_count, self.error_count))
66
 
            self.step.setProgress('tests', self.test_count)
67
 
            self.step.step_status.setStatistic(
68
 
                'tests-total', self.test_count)
69
 
            self.step.step_status.setStatistic(
70
 
                'tests-failures', self.failure_count)
71
 
            self.step.step_status.setStatistic(
72
 
                'tests-errors', self.error_count)
73
 
            self.step.step_status.setText(self.step.describe(False))
74
 
        if self.finished:
75
 
            self.log.finish()
 
4
from bzrbuildbot.subunittest import SubunitObserver
 
5
 
 
6
 
 
7
class TestObserver(
 
8
        buildbot.process.buildstep.LogLineObserver, SubunitObserver):
 
9
    pass
76
10
 
77
11
 
78
12
class Test(buildbot.steps.shell.ShellCommand):