/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2009-08-28 04:13:16 UTC
  • mfrom: (4634.6.8 2.0)
  • mto: This revision was merged to the branch mainline in revision 4660.
  • Revision ID: mbp@sourcefrog.net-20090828041316-adcbxfnfpc4bjtpl
Merge 2.0 back to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
226
226
        self._recordTestStartTime()
227
227
 
228
228
    def startTests(self):
229
 
        self.stream.write(
230
 
            'testing: %s\n' % (osutils.realpath(sys.argv[0]),))
231
 
        self.stream.write(
232
 
            '   %s (%s python%s)\n' % (
233
 
                    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' % (
234
241
                    bzrlib.version_string,
235
242
                    bzrlib._format_version_tuple(sys.version_info),
 
243
                    platform.platform(aliased=1),
236
244
                    ))
237
245
        self.stream.write('\n')
238
246
 
814
822
        self._benchcalls = []
815
823
        self._benchtime = None
816
824
        self._clear_hooks()
817
 
        # Track locks - needs to be called before _clear_debug_flags.
818
825
        self._track_locks()
819
826
        self._clear_debug_flags()
820
827
        TestCase._active_threads = threading.activeCount()
843
850
        self._preserved_debug_flags = set(debug.debug_flags)
844
851
        if 'allow_debug' not in selftest_debug_flags:
845
852
            debug.debug_flags.clear()
 
853
        if 'disable_lock_checks' not in selftest_debug_flags:
 
854
            debug.debug_flags.add('strict_locks')
846
855
        self.addCleanup(self._restore_debug_flags)
847
856
 
848
857
    def _clear_hooks(self):
870
879
 
871
880
    def _check_locks(self):
872
881
        """Check that all lock take/release actions have been paired."""
873
 
        # once we have fixed all the current lock problems, we can change the
874
 
        # following code to always check for mismatched locks, but only do
875
 
        # traceback showing with -Dlock (self._lock_check_thorough is True).
876
 
        # For now, because the test suite will fail, we only assert that lock
877
 
        # 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.
878
885
        # unhook:
879
886
        acquired_locks = [lock for action, lock in self._lock_actions
880
887
                          if action == 'acquired']
899
906
    def _track_locks(self):
900
907
        """Track lock activity during tests."""
901
908
        self._lock_actions = []
902
 
        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
            
903
914
        self.addCleanup(self._check_locks)
904
915
        _mod_lock.Lock.hooks.install_named_hook('lock_acquired',
905
916
                                                self._lock_acquired, None)
1321
1332
        """Make the logfile not be deleted when _finishLogFile is called."""
1322
1333
        self._keep_log_file = True
1323
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
 
1324
1348
    def addCleanup(self, callable, *args, **kwargs):
1325
1349
        """Arrange to run a callable when this case is torn down.
1326
1350
 
1938
1962
        sio.encoding = output_encoding
1939
1963
        return sio
1940
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
 
1941
1975
 
1942
1976
class CapturedCall(object):
1943
1977
    """A helper for capturing smart server calls for easy debug analysis."""
2310
2344
 
2311
2345
    def _getTestDirPrefix(self):
2312
2346
        # create a directory within the top level test directory
2313
 
        if sys.platform == 'win32':
 
2347
        if sys.platform in ('win32', 'cygwin'):
2314
2348
            name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2315
2349
            # windows is likely to have path-length limits so use a short name
2316
2350
            name_prefix = name_prefix[-30:]
2764
2798
        decorators.append(filter_tests(pattern))
2765
2799
    if suite_decorators:
2766
2800
        decorators.extend(suite_decorators)
2767
 
    # tell the result object how many tests will be running:
2768
 
    decorators.append(CountingDecorator)
 
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)
2769
2806
    for decorator in decorators:
2770
2807
        suite = decorator(suite)
2771
2808
    result = runner.run(suite)
3145
3182
 
3146
3183
 
3147
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.
3148
3192
selftest_debug_flags = set()
3149
3193
 
3150
3194
 
3163
3207
             starting_with=None,
3164
3208
             runner_class=None,
3165
3209
             suite_decorators=None,
 
3210
             stream=None,
3166
3211
             ):
3167
3212
    """Run the whole test suite under the enhanced runner"""
3168
3213
    # XXX: Very ugly way to do this...
3185
3230
            keep_only = None
3186
3231
        else:
3187
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]
3188
3236
        if test_suite_factory is None:
 
3237
            # Reduce loading time by loading modules based on the starting_with
 
3238
            # patterns.
3189
3239
            suite = test_suite(keep_only, starting_with)
3190
3240
        else:
3191
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)
3192
3245
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
3193
3246
                     stop_on_failure=stop_on_failure,
3194
3247
                     transport=transport,
3201
3254
                     strict=strict,
3202
3255
                     runner_class=runner_class,
3203
3256
                     suite_decorators=suite_decorators,
 
3257
                     stream=stream,
3204
3258
                     )
3205
3259
    finally:
3206
3260
        default_transport = old_transport
3386
3440
                   'bzrlib.tests.per_lock',
3387
3441
                   'bzrlib.tests.per_transport',
3388
3442
                   'bzrlib.tests.per_tree',
 
3443
                   'bzrlib.tests.per_pack_repository',
3389
3444
                   'bzrlib.tests.per_repository',
3390
3445
                   'bzrlib.tests.per_repository_chk',
3391
3446
                   'bzrlib.tests.per_repository_reference',
 
3447
                   'bzrlib.tests.per_versionedfile',
3392
3448
                   'bzrlib.tests.per_workingtree',
3393
3449
                   'bzrlib.tests.test__annotator',
3394
3450
                   'bzrlib.tests.test__chk_map',
3422
3478
                   'bzrlib.tests.test_config',
3423
3479
                   'bzrlib.tests.test_conflicts',
3424
3480
                   'bzrlib.tests.test_counted_lock',
 
3481
                   'bzrlib.tests.test_crash',
3425
3482
                   'bzrlib.tests.test_decorators',
3426
3483
                   'bzrlib.tests.test_delta',
3427
3484
                   'bzrlib.tests.test_debug',
3460
3517
                   'bzrlib.tests.test_knit',
3461
3518
                   'bzrlib.tests.test_lazy_import',
3462
3519
                   'bzrlib.tests.test_lazy_regex',
 
3520
                   'bzrlib.tests.test_lock',
3463
3521
                   'bzrlib.tests.test_lockable_files',
3464
3522
                   'bzrlib.tests.test_lockdir',
3465
3523
                   'bzrlib.tests.test_log',
3480
3538
                   'bzrlib.tests.test_osutils',
3481
3539
                   'bzrlib.tests.test_osutils_encodings',
3482
3540
                   'bzrlib.tests.test_pack',
3483
 
                   'bzrlib.tests.test_pack_repository',
3484
3541
                   'bzrlib.tests.test_patch',
3485
3542
                   'bzrlib.tests.test_patches',
3486
3543
                   'bzrlib.tests.test_permissions',
3540
3597
                   'bzrlib.tests.test_urlutils',
3541
3598
                   'bzrlib.tests.test_version',
3542
3599
                   'bzrlib.tests.test_version_info',
3543
 
                   'bzrlib.tests.test_versionedfile',
3544
3600
                   'bzrlib.tests.test_weave',
3545
3601
                   'bzrlib.tests.test_whitebox',
3546
3602
                   'bzrlib.tests.test_win32utils',
3555
3611
    if keep_only is not None:
3556
3612
        id_filter = TestIdList(keep_only)
3557
3613
    if starting_with:
3558
 
        starting_with = [test_prefix_alias_registry.resolve_alias(start)
3559
 
                         for start in starting_with]
3560
3614
        # We take precedence over keep_only because *at loading time* using
3561
3615
        # both options means we will load less tests for the same final result.
3562
3616
        def interesting_module(name):
3637
3691
            reload(sys)
3638
3692
            sys.setdefaultencoding(default_encoding)
3639
3693
 
3640
 
    if starting_with:
3641
 
        suite = filter_suite_by_id_startswith(suite, starting_with)
3642
 
 
3643
3694
    if keep_only is not None:
3644
3695
        # Now that the referred modules have loaded their tests, keep only the
3645
3696
        # requested ones.
3773
3824
    try:
3774
3825
        osutils.rmtree(dirname)
3775
3826
    except OSError, e:
3776
 
        if sys.platform == 'win32' and e.errno == errno.EACCES:
3777
 
            sys.stderr.write('Permission denied: '
3778
 
                             'unable to remove testing dir '
3779
 
                             '%s\n%s'
3780
 
                             % (os.path.basename(dirname), e))
3781
 
        else:
3782
 
            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))
3783
3832
 
3784
3833
 
3785
3834
class Feature(object):