~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
import bzrlib.plugin
64
64
import bzrlib.progress as progress
65
65
from bzrlib.revision import common_ancestor
 
66
from bzrlib.revisionspec import RevisionSpec
66
67
import bzrlib.store
67
68
import bzrlib.trace
68
69
from bzrlib.transport import get_transport
136
137
    """
137
138
    stop_early = False
138
139
    
139
 
    def __init__(self, stream, descriptions, verbosity, pb=None):
 
140
    def __init__(self, stream, descriptions, verbosity, pb=None,
 
141
                 bench_history=None):
 
142
        """Construct new TestResult.
 
143
 
 
144
        :param bench_history: Optionally, a writable file object to accumulate
 
145
            benchmark results.
 
146
        """
140
147
        unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
141
148
        self.pb = pb
 
149
        if bench_history is not None:
 
150
            from bzrlib.version import _get_bzr_source_tree
 
151
            src_tree = _get_bzr_source_tree()
 
152
            if src_tree:
 
153
                revision_id = src_tree.last_revision()
 
154
            else:
 
155
                # XXX: If there's no branch, what should we do?
 
156
                revision_id = ''
 
157
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
 
158
        self._bench_history = bench_history
142
159
    
143
160
    def extractBenchmarkTime(self, testCase):
144
161
        """Add a benchmark time for the current test case."""
248
265
 
249
266
    def addSuccess(self, test):
250
267
        self.extractBenchmarkTime(test)
 
268
        if self._bench_history is not None:
 
269
            if self._benchmarkTime is not None:
 
270
                self._bench_history.write("%s %s\n" % (
 
271
                    self._formatTime(self._benchmarkTime),
 
272
                    test.id()))
251
273
        if self.showAll:
252
274
            self.stream.writeln('   OK %s' % self._testTimeString())
253
275
            for bench_called, stats in getattr(test, '_benchcalls', []):
304
326
                 descriptions=0,
305
327
                 verbosity=1,
306
328
                 keep_output=False,
307
 
                 pb=None):
 
329
                 pb=None,
 
330
                 bench_history=None):
308
331
        self.stream = unittest._WritelnDecorator(stream)
309
332
        self.descriptions = descriptions
310
333
        self.verbosity = verbosity
311
334
        self.keep_output = keep_output
312
335
        self.pb = pb
 
336
        self._bench_history = bench_history
313
337
 
314
338
    def _makeResult(self):
315
339
        result = _MyResult(self.stream,
316
340
                           self.descriptions,
317
341
                           self.verbosity,
318
 
                           pb=self.pb)
 
342
                           pb=self.pb,
 
343
                           bench_history=self._bench_history)
319
344
        result.stop_early = self.stop_on_failure
320
345
        return result
321
346
 
395
420
 
396
421
class TestSkipped(Exception):
397
422
    """Indicates that a test was intentionally skipped, rather than failing."""
398
 
    # XXX: Not used yet
399
423
 
400
424
 
401
425
class CommandFailed(Exception):
1209
1233
 
1210
1234
def run_suite(suite, name='test', verbose=False, pattern=".*",
1211
1235
              stop_on_failure=False, keep_output=False,
1212
 
              transport=None, lsprof_timed=None):
 
1236
              transport=None, lsprof_timed=None, bench_history=None):
1213
1237
    TestCaseInTempDir._TEST_NAME = name
1214
1238
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1215
1239
    if verbose:
1222
1246
                            descriptions=0,
1223
1247
                            verbosity=verbosity,
1224
1248
                            keep_output=keep_output,
1225
 
                            pb=pb)
 
1249
                            pb=pb,
 
1250
                            bench_history=bench_history)
1226
1251
    runner.stop_on_failure=stop_on_failure
1227
1252
    if pattern != '.*':
1228
1253
        suite = filter_suite_by_re(suite, pattern)
1234
1259
             keep_output=False,
1235
1260
             transport=None,
1236
1261
             test_suite_factory=None,
1237
 
             lsprof_timed=None):
 
1262
             lsprof_timed=None,
 
1263
             bench_history=None):
1238
1264
    """Run the whole test suite under the enhanced runner"""
1239
1265
    # XXX: Very ugly way to do this...
1240
1266
    # Disable warning about old formats because we don't want it to disturb
1255
1281
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
1256
1282
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
1257
1283
                     transport=transport,
1258
 
                     lsprof_timed=lsprof_timed)
 
1284
                     lsprof_timed=lsprof_timed,
 
1285
                     bench_history=bench_history)
1259
1286
    finally:
1260
1287
        default_transport = old_transport
1261
1288
 
1274
1301
                   'bzrlib.tests.test_branch',
1275
1302
                   'bzrlib.tests.test_bundle',
1276
1303
                   'bzrlib.tests.test_bzrdir',
 
1304
                   'bzrlib.tests.test_cache_utf8',
1277
1305
                   'bzrlib.tests.test_command',
1278
1306
                   'bzrlib.tests.test_commit',
1279
1307
                   'bzrlib.tests.test_commit_merge',
1339
1367
                   'bzrlib.tests.test_upgrade',
1340
1368
                   'bzrlib.tests.test_urlutils',
1341
1369
                   'bzrlib.tests.test_versionedfile',
 
1370
                   'bzrlib.tests.test_version',
1342
1371
                   'bzrlib.tests.test_weave',
1343
1372
                   'bzrlib.tests.test_whitebox',
1344
1373
                   'bzrlib.tests.test_workingtree',