~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2006-01-30 11:55:34 UTC
  • mfrom: (1185.62.24 bzr-jam-pending)
  • Revision ID: mbp@sourcefrog.net-20060130115534-d9ca79b5856a08fa
[merge] jam-pending small fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
            ]
78
78
 
79
79
 
80
 
class EarlyStoppingTestResultAdapter(object):
81
 
    """An adapter for TestResult to stop at the first first failure or error"""
82
 
 
83
 
    def __init__(self, result):
84
 
        self._result = result
85
 
 
86
 
    def addError(self, test, err):
87
 
        self._result.addError(test, err)
88
 
        self._result.stop()
89
 
 
90
 
    def addFailure(self, test, err):
91
 
        self._result.addFailure(test, err)
92
 
        self._result.stop()
93
 
 
94
 
    def __getattr__(self, name):
95
 
        return getattr(self._result, name)
96
 
 
97
 
    def __setattr__(self, name, value):
98
 
        if name == '_result':
99
 
            object.__setattr__(self, name, value)
100
 
        return setattr(self._result, name, value)
101
 
 
102
 
 
103
80
class _MyResult(unittest._TextTestResult):
104
81
    """Custom TestResult.
105
82
 
106
83
    Shows output in a different format, including displaying runtime for tests.
107
84
    """
 
85
    stop_early = False
108
86
 
109
87
    def _elapsedTime(self):
110
88
        return "%5dms" % (1000 * (time.time() - self._start_time))
144
122
        elif self.dots:
145
123
            self.stream.write('E')
146
124
        self.stream.flush()
 
125
        if self.stop_early:
 
126
            self.stop()
147
127
 
148
128
    def addFailure(self, test, err):
149
129
        unittest.TestResult.addFailure(self, test, err)
152
132
        elif self.dots:
153
133
            self.stream.write('F')
154
134
        self.stream.flush()
 
135
        if self.stop_early:
 
136
            self.stop()
155
137
 
156
138
    def addSuccess(self, test):
157
139
        if self.showAll:
192
174
 
193
175
    def _makeResult(self):
194
176
        result = _MyResult(self.stream, self.descriptions, self.verbosity)
195
 
        if self.stop_on_failure:
196
 
            result = EarlyStoppingTestResultAdapter(result)
 
177
        result.stop_early = self.stop_on_failure
197
178
        return result
198
179
 
199
180