~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-14 16:16:53 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1919.
  • Revision ID: john@arbash-meinel.com-20060814161653-54cdcdadcd4e9003
Remove bogus entry from BRANCH.TODO

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
67
66
import bzrlib.store
68
 
from bzrlib import symbol_versioning
69
67
import bzrlib.trace
70
68
from bzrlib.transport import get_transport
71
69
import bzrlib.transport
138
136
    """
139
137
    stop_early = False
140
138
    
141
 
    def __init__(self, stream, descriptions, verbosity, pb=None,
142
 
                 bench_history=None):
143
 
        """Construct new TestResult.
144
 
 
145
 
        :param bench_history: Optionally, a writable file object to accumulate
146
 
            benchmark results.
147
 
        """
 
139
    def __init__(self, stream, descriptions, verbosity, pb=None):
148
140
        unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
149
141
        self.pb = pb
150
 
        if bench_history is not None:
151
 
            from bzrlib.version import _get_bzr_source_tree
152
 
            src_tree = _get_bzr_source_tree()
153
 
            if src_tree:
154
 
                revision_id = src_tree.last_revision()
155
 
            else:
156
 
                # XXX: If there's no branch, what should we do?
157
 
                revision_id = ''
158
 
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
159
 
        self._bench_history = bench_history
160
142
    
161
143
    def extractBenchmarkTime(self, testCase):
162
144
        """Add a benchmark time for the current test case."""
266
248
 
267
249
    def addSuccess(self, test):
268
250
        self.extractBenchmarkTime(test)
269
 
        if self._bench_history is not None:
270
 
            if self._benchmarkTime is not None:
271
 
                self._bench_history.write("%s %s\n" % (
272
 
                    self._formatTime(self._benchmarkTime),
273
 
                    test.id()))
274
251
        if self.showAll:
275
252
            self.stream.writeln('   OK %s' % self._testTimeString())
276
253
            for bench_called, stats in getattr(test, '_benchcalls', []):
327
304
                 descriptions=0,
328
305
                 verbosity=1,
329
306
                 keep_output=False,
330
 
                 pb=None,
331
 
                 bench_history=None):
 
307
                 pb=None):
332
308
        self.stream = unittest._WritelnDecorator(stream)
333
309
        self.descriptions = descriptions
334
310
        self.verbosity = verbosity
335
311
        self.keep_output = keep_output
336
312
        self.pb = pb
337
 
        self._bench_history = bench_history
338
313
 
339
314
    def _makeResult(self):
340
315
        result = _MyResult(self.stream,
341
316
                           self.descriptions,
342
317
                           self.verbosity,
343
 
                           pb=self.pb,
344
 
                           bench_history=self._bench_history)
 
318
                           pb=self.pb)
345
319
        result.stop_early = self.stop_on_failure
346
320
        return result
347
321
 
421
395
 
422
396
class TestSkipped(Exception):
423
397
    """Indicates that a test was intentionally skipped, rather than failing."""
 
398
    # XXX: Not used yet
424
399
 
425
400
 
426
401
class CommandFailed(Exception):
577
552
            self.fail("%r is an instance of %s rather than %s" % (
578
553
                obj, obj.__class__, kls))
579
554
 
580
 
    def assertDeprecated(self, expected, callable, *args, **kwargs):
581
 
        """Assert that a callable is deprecated in a particular way.
582
 
 
583
 
        :param expected: a list of the deprecation warnings expected, in order
584
 
        :param callable: The callable to call
585
 
        :param args: The positional arguments for the callable
586
 
        :param kwargs: The keyword arguments for the callable
587
 
        """
588
 
        local_warnings = []
589
 
        def capture_warnings(msg, cls, stacklevel=None):
590
 
            self.assertEqual(cls, DeprecationWarning)
591
 
            local_warnings.append(msg)
592
 
        method = symbol_versioning.warn
593
 
        symbol_versioning.set_warning_method(capture_warnings)
594
 
        try:
595
 
            callable(*args, **kwargs)
596
 
        finally:
597
 
            result = symbol_versioning.set_warning_method(method)
598
 
        self.assertEqual(expected, local_warnings)
599
 
        return result
600
 
 
601
555
    def _startLogFile(self):
602
556
        """Send bzr and test log messages to a temporary file.
603
557
 
1255
1209
 
1256
1210
def run_suite(suite, name='test', verbose=False, pattern=".*",
1257
1211
              stop_on_failure=False, keep_output=False,
1258
 
              transport=None, lsprof_timed=None, bench_history=None):
 
1212
              transport=None, lsprof_timed=None):
1259
1213
    TestCaseInTempDir._TEST_NAME = name
1260
1214
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1261
1215
    if verbose:
1268
1222
                            descriptions=0,
1269
1223
                            verbosity=verbosity,
1270
1224
                            keep_output=keep_output,
1271
 
                            pb=pb,
1272
 
                            bench_history=bench_history)
 
1225
                            pb=pb)
1273
1226
    runner.stop_on_failure=stop_on_failure
1274
1227
    if pattern != '.*':
1275
1228
        suite = filter_suite_by_re(suite, pattern)
1281
1234
             keep_output=False,
1282
1235
             transport=None,
1283
1236
             test_suite_factory=None,
1284
 
             lsprof_timed=None,
1285
 
             bench_history=None):
 
1237
             lsprof_timed=None):
1286
1238
    """Run the whole test suite under the enhanced runner"""
1287
1239
    # XXX: Very ugly way to do this...
1288
1240
    # Disable warning about old formats because we don't want it to disturb
1303
1255
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
1304
1256
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
1305
1257
                     transport=transport,
1306
 
                     lsprof_timed=lsprof_timed,
1307
 
                     bench_history=bench_history)
 
1258
                     lsprof_timed=lsprof_timed)
1308
1259
    finally:
1309
1260
        default_transport = old_transport
1310
1261
 
1323
1274
                   'bzrlib.tests.test_branch',
1324
1275
                   'bzrlib.tests.test_bundle',
1325
1276
                   'bzrlib.tests.test_bzrdir',
1326
 
                   'bzrlib.tests.test_cache_utf8',
1327
1277
                   'bzrlib.tests.test_command',
1328
1278
                   'bzrlib.tests.test_commit',
1329
1279
                   'bzrlib.tests.test_commit_merge',
1389
1339
                   'bzrlib.tests.test_upgrade',
1390
1340
                   'bzrlib.tests.test_urlutils',
1391
1341
                   'bzrlib.tests.test_versionedfile',
1392
 
                   'bzrlib.tests.test_version',
1393
1342
                   'bzrlib.tests.test_weave',
1394
1343
                   'bzrlib.tests.test_whitebox',
1395
1344
                   'bzrlib.tests.test_workingtree',