~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

merge 2.0 branch rev 4647

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
                          TestLoader,
103
103
                          )
104
104
from bzrlib.tests.treeshape import build_tree_contents
 
105
from bzrlib.ui import NullProgressView
 
106
from bzrlib.ui.text import TextUIFactory
105
107
import bzrlib.version_info_formats.format_custom
106
108
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
107
109
 
112
114
 
113
115
default_transport = LocalURLServer
114
116
 
 
117
# Subunit result codes, defined here to prevent a hard dependency on subunit.
 
118
SUBUNIT_SEEK_SET = 0
 
119
SUBUNIT_SEEK_CUR = 1
 
120
 
115
121
 
116
122
class ExtendedTestResult(unittest._TextTestResult):
117
123
    """Accepts, reports and accumulates the results of running tests.
133
139
 
134
140
    def __init__(self, stream, descriptions, verbosity,
135
141
                 bench_history=None,
136
 
                 num_tests=None,
137
142
                 strict=False,
138
143
                 ):
139
144
        """Construct new TestResult.
158
163
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
159
164
        self._bench_history = bench_history
160
165
        self.ui = ui.ui_factory
161
 
        self.num_tests = num_tests
 
166
        self.num_tests = 0
162
167
        self.error_count = 0
163
168
        self.failure_count = 0
164
169
        self.known_failure_count = 0
170
175
        self._strict = strict
171
176
 
172
177
    def done(self):
 
178
        # nb: called stopTestRun in the version of this that Python merged
 
179
        # upstream, according to lifeless 20090803
173
180
        if self._strict:
174
181
            ok = self.wasStrictlySuccessful()
175
182
        else:
195
202
    def _testTimeString(self, testCase):
196
203
        benchmark_time = self._extractBenchmarkTime(testCase)
197
204
        if benchmark_time is not None:
198
 
            return "%s/%s" % (
199
 
                self._formatTime(benchmark_time),
200
 
                self._elapsedTestTimeString())
 
205
            return self._formatTime(benchmark_time) + "*"
201
206
        else:
202
 
            return "           %s" % self._elapsedTestTimeString()
 
207
            return self._elapsedTestTimeString()
203
208
 
204
209
    def _formatTime(self, seconds):
205
210
        """Format seconds as milliseconds with leading spaces."""
221
226
        self._recordTestStartTime()
222
227
 
223
228
    def startTests(self):
224
 
        self.stream.write(
225
 
            'testing: %s\n' % (osutils.realpath(sys.argv[0]),))
226
 
        self.stream.write(
227
 
            '   %s (%s python%s)\n' % (
228
 
                    bzrlib.__path__[0],
 
229
        import platform
 
230
        if getattr(sys, 'frozen', None) is None:
 
231
            bzr_path = osutils.realpath(sys.argv[0])
 
232
        else:
 
233
            bzr_path = sys.executable
 
234
        self.stream.write(
 
235
            'testing: %s\n' % (bzr_path,))
 
236
        self.stream.write(
 
237
            '   %s\n' % (
 
238
                    bzrlib.__path__[0],))
 
239
        self.stream.write(
 
240
            '   bzr-%s python-%s %s\n' % (
229
241
                    bzrlib.version_string,
230
242
                    bzrlib._format_version_tuple(sys.version_info),
 
243
                    platform.platform(aliased=1),
231
244
                    ))
232
245
        self.stream.write('\n')
233
246
 
346
359
            self.stream.write("%s: " % flavour)
347
360
            self.stream.writeln(self.getDescription(test))
348
361
            if getattr(test, '_get_log', None) is not None:
349
 
                self.stream.write('\n')
350
 
                self.stream.write(
351
 
                        ('vvvv[log from %s]' % test.id()).ljust(78,'-'))
352
 
                self.stream.write('\n')
353
 
                self.stream.write(test._get_log())
354
 
                self.stream.write('\n')
355
 
                self.stream.write(
356
 
                        ('^^^^[log from %s]' % test.id()).ljust(78,'-'))
357
 
                self.stream.write('\n')
 
362
                log_contents = test._get_log()
 
363
                if log_contents:
 
364
                    self.stream.write('\n')
 
365
                    self.stream.write(
 
366
                            ('vvvv[log from %s]' % test.id()).ljust(78,'-'))
 
367
                    self.stream.write('\n')
 
368
                    self.stream.write(log_contents)
 
369
                    self.stream.write('\n')
 
370
                    self.stream.write(
 
371
                            ('^^^^[log from %s]' % test.id()).ljust(78,'-'))
 
372
                    self.stream.write('\n')
358
373
            self.stream.writeln(self.separator2)
359
374
            self.stream.writeln("%s" % err)
360
375
 
 
376
    def progress(self, offset, whence):
 
377
        """The test is adjusting the count of tests to run."""
 
378
        if whence == SUBUNIT_SEEK_SET:
 
379
            self.num_tests = offset
 
380
        elif whence == SUBUNIT_SEEK_CUR:
 
381
            self.num_tests += offset
 
382
        else:
 
383
            raise errors.BzrError("Unknown whence %r" % whence)
 
384
 
361
385
    def finished(self):
362
386
        pass
363
387
 
378
402
 
379
403
    def __init__(self, stream, descriptions, verbosity,
380
404
                 bench_history=None,
381
 
                 num_tests=None,
382
405
                 pb=None,
383
406
                 strict=None,
384
407
                 ):
385
408
        ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
386
 
            bench_history, num_tests, strict)
387
 
        if pb is None:
388
 
            self.pb = self.ui.nested_progress_bar()
389
 
            self._supplied_pb = False
390
 
        else:
391
 
            self.pb = pb
392
 
            self._supplied_pb = True
 
409
            bench_history, strict)
 
410
        # We no longer pass them around, but just rely on the UIFactory stack
 
411
        # for state
 
412
        if pb is not None:
 
413
            warnings.warn("Passing pb to TextTestResult is deprecated")
 
414
        self.pb = self.ui.nested_progress_bar()
393
415
        self.pb.show_pct = False
394
416
        self.pb.show_spinner = False
395
417
        self.pb.show_eta = False,
396
418
        self.pb.show_count = False
397
419
        self.pb.show_bar = False
 
420
        self.pb.update_latency = 0
 
421
        self.pb.show_transport_activity = False
 
422
 
 
423
    def done(self):
 
424
        # called when the tests that are going to run have run
 
425
        self.pb.clear()
 
426
        super(TextTestResult, self).done()
 
427
 
 
428
    def finished(self):
 
429
        self.pb.finished()
398
430
 
399
431
    def report_starting(self):
400
432
        self.pb.update('[test 0/%d] Starting' % (self.num_tests))
401
433
 
 
434
    def printErrors(self):
 
435
        # clear the pb to make room for the error listing
 
436
        self.pb.clear()
 
437
        super(TextTestResult, self).printErrors()
 
438
 
402
439
    def _progress_prefix_text(self):
403
440
        # the longer this text, the less space we have to show the test
404
441
        # name...
409
446
        ##     a += ', %d skip' % self.skip_count
410
447
        ## if self.known_failure_count:
411
448
        ##     a += '+%dX' % self.known_failure_count
412
 
        if self.num_tests is not None:
 
449
        if self.num_tests:
413
450
            a +='/%d' % self.num_tests
414
451
        a += ' in '
415
452
        runtime = time.time() - self._overall_start_time
464
501
    def report_cleaning_up(self):
465
502
        self.pb.update('Cleaning up')
466
503
 
467
 
    def finished(self):
468
 
        if not self._supplied_pb:
469
 
            self.pb.finished()
470
 
 
471
504
 
472
505
class VerboseTestResult(ExtendedTestResult):
473
506
    """Produce long output, with one line per test run plus times"""
486
519
    def report_test_start(self, test):
487
520
        self.count += 1
488
521
        name = self._shortened_test_description(test)
489
 
        # width needs space for 6 char status, plus 1 for slash, plus 2 10-char
490
 
        # numbers, plus a trailing blank
 
522
        # width needs space for 6 char status, plus 1 for slash, plus an
 
523
        # 11-char time string, plus a trailing blank
491
524
        # when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
492
525
        self.stream.write(self._ellipsize_to_right(name,
493
 
                          osutils.terminal_width()-30))
 
526
                          osutils.terminal_width()-18))
494
527
        self.stream.flush()
495
528
 
496
529
    def _error_summary(self, err):
565
598
                              self.descriptions,
566
599
                              self.verbosity,
567
600
                              bench_history=self._bench_history,
568
 
                              num_tests=test.countTestCases(),
569
601
                              strict=self._strict,
570
602
                              )
571
603
        result.stop_early = self.stop_on_failure
702
734
            return setattr(self._cstring, name, val)
703
735
 
704
736
 
705
 
class TestUIFactory(ui.CLIUIFactory):
 
737
class TestUIFactory(TextUIFactory):
706
738
    """A UI Factory for testing.
707
739
 
708
740
    Hide the progress bar but emit note()s.
709
741
    Redirect stdin.
710
742
    Allows get_password to be tested without real tty attached.
 
743
 
 
744
    See also CannedInputUIFactory which lets you provide programmatic input in
 
745
    a structured way.
711
746
    """
 
747
    # TODO: Capture progress events at the model level and allow them to be
 
748
    # observed by tests that care.
 
749
    #
 
750
    # XXX: Should probably unify more with CannedInputUIFactory or a
 
751
    # particular configuration of TextUIFactory, or otherwise have a clearer
 
752
    # idea of how they're supposed to be different.
 
753
    # See https://bugs.edge.launchpad.net/bzr/+bug/408213
712
754
 
713
755
    def __init__(self, stdout=None, stderr=None, stdin=None):
714
756
        if stdin is not None:
719
761
            stdin = StringIOWrapper(stdin)
720
762
        super(TestUIFactory, self).__init__(stdin, stdout, stderr)
721
763
 
722
 
    def clear(self):
723
 
        """See progress.ProgressBar.clear()."""
724
 
 
725
 
    def clear_term(self):
726
 
        """See progress.ProgressBar.clear_term()."""
727
 
 
728
 
    def finished(self):
729
 
        """See progress.ProgressBar.finished()."""
730
 
 
731
 
    def note(self, fmt_string, *args):
732
 
        """See progress.ProgressBar.note()."""
733
 
        if args:
734
 
            fmt_string = fmt_string % args
735
 
        self.stdout.write(fmt_string + "\n")
736
 
 
737
 
    def progress_bar(self):
738
 
        return self
739
 
 
740
 
    def nested_progress_bar(self):
741
 
        return self
742
 
 
743
 
    def update(self, message, count=None, total=None):
744
 
        """See progress.ProgressBar.update()."""
745
 
 
746
764
    def get_non_echoed_password(self):
747
765
        """Get password from stdin without trying to handle the echo mode"""
748
766
        password = self.stdin.readline()
752
770
            password = password[:-1]
753
771
        return password
754
772
 
 
773
    def make_progress_view(self):
 
774
        return NullProgressView()
 
775
 
755
776
 
756
777
class TestCase(unittest.TestCase):
757
778
    """Base class for bzr unit tests.
801
822
        self._benchcalls = []
802
823
        self._benchtime = None
803
824
        self._clear_hooks()
804
 
        # Track locks - needs to be called before _clear_debug_flags.
805
825
        self._track_locks()
806
826
        self._clear_debug_flags()
807
827
        TestCase._active_threads = threading.activeCount()
830
850
        self._preserved_debug_flags = set(debug.debug_flags)
831
851
        if 'allow_debug' not in selftest_debug_flags:
832
852
            debug.debug_flags.clear()
 
853
        if 'disable_lock_checks' not in selftest_debug_flags:
 
854
            debug.debug_flags.add('strict_locks')
833
855
        self.addCleanup(self._restore_debug_flags)
834
856
 
835
857
    def _clear_hooks(self):
857
879
 
858
880
    def _check_locks(self):
859
881
        """Check that all lock take/release actions have been paired."""
860
 
        # once we have fixed all the current lock problems, we can change the
861
 
        # following code to always check for mismatched locks, but only do
862
 
        # traceback showing with -Dlock (self._lock_check_thorough is True).
863
 
        # For now, because the test suite will fail, we only assert that lock
864
 
        # matching has occured with -Dlock.
 
882
        # We always check for mismatched locks. If a mismatch is found, we
 
883
        # fail unless -Edisable_lock_checks is supplied to selftest, in which
 
884
        # case we just print a warning.
865
885
        # unhook:
866
886
        acquired_locks = [lock for action, lock in self._lock_actions
867
887
                          if action == 'acquired']
886
906
    def _track_locks(self):
887
907
        """Track lock activity during tests."""
888
908
        self._lock_actions = []
889
 
        self._lock_check_thorough = 'lock' not in debug.debug_flags
 
909
        if 'disable_lock_checks' in selftest_debug_flags:
 
910
            self._lock_check_thorough = False
 
911
        else:
 
912
            self._lock_check_thorough = True
 
913
            
890
914
        self.addCleanup(self._check_locks)
891
915
        _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
892
916
                                                self._lock_acquired, None)
1093
1117
                         osutils.realpath(path2),
1094
1118
                         "apparent paths:\na = %s\nb = %s\n," % (path1, path2))
1095
1119
 
1096
 
    def assertIsInstance(self, obj, kls):
1097
 
        """Fail if obj is not an instance of kls"""
 
1120
    def assertIsInstance(self, obj, kls, msg=None):
 
1121
        """Fail if obj is not an instance of kls
 
1122
        
 
1123
        :param msg: Supplementary message to show if the assertion fails.
 
1124
        """
1098
1125
        if not isinstance(obj, kls):
1099
 
            self.fail("%r is an instance of %s rather than %s" % (
1100
 
                obj, obj.__class__, kls))
 
1126
            m = "%r is an instance of %s rather than %s" % (
 
1127
                obj, obj.__class__, kls)
 
1128
            if msg:
 
1129
                m += ": " + msg
 
1130
            self.fail(m)
1101
1131
 
1102
1132
    def expectFailure(self, reason, assertion, *args, **kwargs):
1103
1133
        """Invoke a test, expecting it to fail for the given reason.
1302
1332
        """Make the logfile not be deleted when _finishLogFile is called."""
1303
1333
        self._keep_log_file = True
1304
1334
 
 
1335
    def thisFailsStrictLockCheck(self):
 
1336
        """It is known that this test would fail with -Dstrict_locks.
 
1337
 
 
1338
        By default, all tests are run with strict lock checking unless
 
1339
        -Edisable_lock_checks is supplied. However there are some tests which
 
1340
        we know fail strict locks at this point that have not been fixed.
 
1341
        They should call this function to disable the strict checking.
 
1342
 
 
1343
        This should be used sparingly, it is much better to fix the locking
 
1344
        issues rather than papering over the problem by calling this function.
 
1345
        """
 
1346
        debug.debug_flags.discard('strict_locks')
 
1347
 
1305
1348
    def addCleanup(self, callable, *args, **kwargs):
1306
1349
        """Arrange to run a callable when this case is torn down.
1307
1350
 
1325
1368
            'BZR_PROGRESS_BAR': None,
1326
1369
            'BZR_LOG': None,
1327
1370
            'BZR_PLUGIN_PATH': None,
 
1371
            # Make sure that any text ui tests are consistent regardless of
 
1372
            # the environment the test case is run in; you may want tests that
 
1373
            # test other combinations.  'dumb' is a reasonable guess for tests
 
1374
            # going to a pipe or a StringIO.
 
1375
            'TERM': 'dumb',
 
1376
            'LINES': '25',
 
1377
            'COLUMNS': '80',
1328
1378
            # SSH Agent
1329
1379
            'SSH_AUTH_SOCK': None,
1330
1380
            # Proxies
1912
1962
        sio.encoding = output_encoding
1913
1963
        return sio
1914
1964
 
 
1965
    def disable_verb(self, verb):
 
1966
        """Disable a smart server verb for one test."""
 
1967
        from bzrlib.smart import request
 
1968
        request_handlers = request.request_handlers
 
1969
        orig_method = request_handlers.get(verb)
 
1970
        request_handlers.remove(verb)
 
1971
        def restoreVerb():
 
1972
            request_handlers.register(verb, orig_method)
 
1973
        self.addCleanup(restoreVerb)
 
1974
 
1915
1975
 
1916
1976
class CapturedCall(object):
1917
1977
    """A helper for capturing smart server calls for easy debug analysis."""
2284
2344
 
2285
2345
    def _getTestDirPrefix(self):
2286
2346
        # create a directory within the top level test directory
2287
 
        if sys.platform == 'win32':
 
2347
        if sys.platform in ('win32', 'cygwin'):
2288
2348
            name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2289
2349
            # windows is likely to have path-length limits so use a short name
2290
2350
            name_prefix = name_prefix[-30:]
2738
2798
        decorators.append(filter_tests(pattern))
2739
2799
    if suite_decorators:
2740
2800
        decorators.extend(suite_decorators)
 
2801
    # tell the result object how many tests will be running: (except if
 
2802
    # --parallel=fork is being used. Robert said he will provide a better
 
2803
    # progress design later -- vila 20090817)
 
2804
    if fork_decorator not in decorators:
 
2805
        decorators.append(CountingDecorator)
2741
2806
    for decorator in decorators:
2742
2807
        suite = decorator(suite)
2743
2808
    result = runner.run(suite)
2847
2912
        return result
2848
2913
 
2849
2914
 
 
2915
class CountingDecorator(TestDecorator):
 
2916
    """A decorator which calls result.progress(self.countTestCases)."""
 
2917
 
 
2918
    def run(self, result):
 
2919
        progress_method = getattr(result, 'progress', None)
 
2920
        if callable(progress_method):
 
2921
            progress_method(self.countTestCases(), SUBUNIT_SEEK_SET)
 
2922
        return super(CountingDecorator, self).run(result)
 
2923
 
 
2924
 
2850
2925
class ExcludeDecorator(TestDecorator):
2851
2926
    """A decorator which excludes test matching an exclude pattern."""
2852
2927
 
2959
3034
    concurrency = osutils.local_concurrency()
2960
3035
    result = []
2961
3036
    from subunit import TestProtocolClient, ProtocolTestCase
 
3037
    try:
 
3038
        from subunit.test_results import AutoTimingTestResultDecorator
 
3039
    except ImportError:
 
3040
        AutoTimingTestResultDecorator = lambda x:x
2962
3041
    class TestInOtherProcess(ProtocolTestCase):
2963
3042
        # Should be in subunit, I think. RBC.
2964
3043
        def __init__(self, stream, pid):
2987
3066
                sys.stdin.close()
2988
3067
                sys.stdin = None
2989
3068
                stream = os.fdopen(c2pwrite, 'wb', 1)
2990
 
                subunit_result = TestProtocolClient(stream)
 
3069
                subunit_result = AutoTimingTestResultDecorator(
 
3070
                    TestProtocolClient(stream))
2991
3071
                process_suite.run(subunit_result)
2992
3072
            finally:
2993
3073
                os._exit(0)
3007
3087
    """
3008
3088
    concurrency = osutils.local_concurrency()
3009
3089
    result = []
3010
 
    from subunit import TestProtocolClient, ProtocolTestCase
 
3090
    from subunit import ProtocolTestCase
3011
3091
    class TestInSubprocess(ProtocolTestCase):
3012
3092
        def __init__(self, process, name):
3013
3093
            ProtocolTestCase.__init__(self, process.stdout)
3102
3182
 
3103
3183
 
3104
3184
# Controlled by "bzr selftest -E=..." option
 
3185
# Currently supported:
 
3186
#   -Eallow_debug           Will no longer clear debug.debug_flags() so it
 
3187
#                           preserves any flags supplied at the command line.
 
3188
#   -Edisable_lock_checks   Turns errors in mismatched locks into simple prints
 
3189
#                           rather than failing tests. And no longer raise
 
3190
#                           LockContention when fctnl locks are not being used
 
3191
#                           with proper exclusion rules.
3105
3192
selftest_debug_flags = set()
3106
3193
 
3107
3194
 
3120
3207
             starting_with=None,
3121
3208
             runner_class=None,
3122
3209
             suite_decorators=None,
 
3210
             stream=None,
3123
3211
             ):
3124
3212
    """Run the whole test suite under the enhanced runner"""
3125
3213
    # XXX: Very ugly way to do this...
3142
3230
            keep_only = None
3143
3231
        else:
3144
3232
            keep_only = load_test_id_list(load_list)
 
3233
        if starting_with:
 
3234
            starting_with = [test_prefix_alias_registry.resolve_alias(start)
 
3235
                             for start in starting_with]
3145
3236
        if test_suite_factory is None:
 
3237
            # Reduce loading time by loading modules based on the starting_with
 
3238
            # patterns.
3146
3239
            suite = test_suite(keep_only, starting_with)
3147
3240
        else:
3148
3241
            suite = test_suite_factory()
 
3242
        if starting_with:
 
3243
            # But always filter as requested.
 
3244
            suite = filter_suite_by_id_startswith(suite, starting_with)
3149
3245
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
3150
3246
                     stop_on_failure=stop_on_failure,
3151
3247
                     transport=transport,
3158
3254
                     strict=strict,
3159
3255
                     runner_class=runner_class,
3160
3256
                     suite_decorators=suite_decorators,
 
3257
                     stream=stream,
3161
3258
                     )
3162
3259
    finally:
3163
3260
        default_transport = old_transport
3333
3430
    testmod_names = [
3334
3431
                   'bzrlib.doc',
3335
3432
                   'bzrlib.tests.blackbox',
3336
 
                   'bzrlib.tests.branch_implementations',
3337
 
                   'bzrlib.tests.bzrdir_implementations',
3338
3433
                   'bzrlib.tests.commands',
3339
 
                   'bzrlib.tests.interrepository_implementations',
3340
 
                   'bzrlib.tests.intertree_implementations',
3341
 
                   'bzrlib.tests.inventory_implementations',
 
3434
                   'bzrlib.tests.per_branch',
 
3435
                   'bzrlib.tests.per_bzrdir',
 
3436
                   'bzrlib.tests.per_interrepository',
 
3437
                   'bzrlib.tests.per_intertree',
 
3438
                   'bzrlib.tests.per_inventory',
3342
3439
                   'bzrlib.tests.per_interbranch',
3343
3440
                   'bzrlib.tests.per_lock',
 
3441
                   'bzrlib.tests.per_transport',
 
3442
                   'bzrlib.tests.per_tree',
 
3443
                   'bzrlib.tests.per_pack_repository',
3344
3444
                   'bzrlib.tests.per_repository',
3345
3445
                   'bzrlib.tests.per_repository_chk',
3346
3446
                   'bzrlib.tests.per_repository_reference',
 
3447
                   'bzrlib.tests.per_versionedfile',
 
3448
                   'bzrlib.tests.per_workingtree',
 
3449
                   'bzrlib.tests.test__annotator',
3347
3450
                   'bzrlib.tests.test__chk_map',
3348
3451
                   'bzrlib.tests.test__dirstate_helpers',
3349
3452
                   'bzrlib.tests.test__groupcompress',
 
3453
                   'bzrlib.tests.test__known_graph',
3350
3454
                   'bzrlib.tests.test__rio',
3351
3455
                   'bzrlib.tests.test__walkdirs_win32',
3352
3456
                   'bzrlib.tests.test_ancestry',
3374
3478
                   'bzrlib.tests.test_config',
3375
3479
                   'bzrlib.tests.test_conflicts',
3376
3480
                   'bzrlib.tests.test_counted_lock',
 
3481
                   'bzrlib.tests.test_crash',
3377
3482
                   'bzrlib.tests.test_decorators',
3378
3483
                   'bzrlib.tests.test_delta',
3379
3484
                   'bzrlib.tests.test_debug',
3412
3517
                   'bzrlib.tests.test_knit',
3413
3518
                   'bzrlib.tests.test_lazy_import',
3414
3519
                   'bzrlib.tests.test_lazy_regex',
 
3520
                   'bzrlib.tests.test_lock',
3415
3521
                   'bzrlib.tests.test_lockable_files',
3416
3522
                   'bzrlib.tests.test_lockdir',
3417
3523
                   'bzrlib.tests.test_log',
3432
3538
                   'bzrlib.tests.test_osutils',
3433
3539
                   'bzrlib.tests.test_osutils_encodings',
3434
3540
                   'bzrlib.tests.test_pack',
3435
 
                   'bzrlib.tests.test_pack_repository',
3436
3541
                   'bzrlib.tests.test_patch',
3437
3542
                   'bzrlib.tests.test_patches',
3438
3543
                   'bzrlib.tests.test_permissions',
3480
3585
                   'bzrlib.tests.test_transactions',
3481
3586
                   'bzrlib.tests.test_transform',
3482
3587
                   'bzrlib.tests.test_transport',
3483
 
                   'bzrlib.tests.test_transport_implementations',
3484
3588
                   'bzrlib.tests.test_transport_log',
3485
3589
                   'bzrlib.tests.test_tree',
3486
3590
                   'bzrlib.tests.test_treebuilder',
3493
3597
                   'bzrlib.tests.test_urlutils',
3494
3598
                   'bzrlib.tests.test_version',
3495
3599
                   'bzrlib.tests.test_version_info',
3496
 
                   'bzrlib.tests.test_versionedfile',
3497
3600
                   'bzrlib.tests.test_weave',
3498
3601
                   'bzrlib.tests.test_whitebox',
3499
3602
                   'bzrlib.tests.test_win32utils',
3501
3604
                   'bzrlib.tests.test_workingtree_4',
3502
3605
                   'bzrlib.tests.test_wsgi',
3503
3606
                   'bzrlib.tests.test_xml',
3504
 
                   'bzrlib.tests.tree_implementations',
3505
 
                   'bzrlib.tests.workingtree_implementations',
3506
3607
                   ]
3507
3608
 
3508
3609
    loader = TestUtil.TestLoader()
3509
3610
 
 
3611
    if keep_only is not None:
 
3612
        id_filter = TestIdList(keep_only)
3510
3613
    if starting_with:
3511
 
        starting_with = [test_prefix_alias_registry.resolve_alias(start)
3512
 
                         for start in starting_with]
3513
3614
        # We take precedence over keep_only because *at loading time* using
3514
3615
        # both options means we will load less tests for the same final result.
3515
3616
        def interesting_module(name):
3525
3626
        loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
3526
3627
 
3527
3628
    elif keep_only is not None:
3528
 
        id_filter = TestIdList(keep_only)
3529
3629
        loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
3530
3630
        def interesting_module(name):
3531
3631
            return id_filter.refers_to(name)
3591
3691
            reload(sys)
3592
3692
            sys.setdefaultencoding(default_encoding)
3593
3693
 
3594
 
    if starting_with:
3595
 
        suite = filter_suite_by_id_startswith(suite, starting_with)
3596
 
 
3597
3694
    if keep_only is not None:
3598
3695
        # Now that the referred modules have loaded their tests, keep only the
3599
3696
        # requested ones.
3727
3824
    try:
3728
3825
        osutils.rmtree(dirname)
3729
3826
    except OSError, e:
3730
 
        if sys.platform == 'win32' and e.errno == errno.EACCES:
3731
 
            sys.stderr.write('Permission denied: '
3732
 
                             'unable to remove testing dir '
3733
 
                             '%s\n%s'
3734
 
                             % (os.path.basename(dirname), e))
3735
 
        else:
3736
 
            raise
 
3827
        # We don't want to fail here because some useful display will be lost
 
3828
        # otherwise. Polluting the tmp dir is bad, but not giving all the
 
3829
        # possible info to the test runner is even worse.
 
3830
        sys.stderr.write('Unable to remove testing dir %s\n%s'
 
3831
                         % (os.path.basename(dirname), e))
3737
3832
 
3738
3833
 
3739
3834
class Feature(object):
3978
4073
# Only define SubUnitBzrRunner if subunit is available.
3979
4074
try:
3980
4075
    from subunit import TestProtocolClient
 
4076
    try:
 
4077
        from subunit.test_results import AutoTimingTestResultDecorator
 
4078
    except ImportError:
 
4079
        AutoTimingTestResultDecorator = lambda x:x
3981
4080
    class SubUnitBzrRunner(TextTestRunner):
3982
4081
        def run(self, test):
3983
 
            result = TestProtocolClient(self.stream)
 
4082
            result = AutoTimingTestResultDecorator(
 
4083
                TestProtocolClient(self.stream))
3984
4084
            test.run(result)
3985
4085
            return result
3986
4086
except ImportError: