/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

Merge bzr.dev into cleanup

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
 
3386
3430
                   'bzrlib.tests.per_lock',
3387
3431
                   'bzrlib.tests.per_transport',
3388
3432
                   'bzrlib.tests.per_tree',
 
3433
                   'bzrlib.tests.per_pack_repository',
3389
3434
                   'bzrlib.tests.per_repository',
3390
3435
                   'bzrlib.tests.per_repository_chk',
3391
3436
                   'bzrlib.tests.per_repository_reference',
 
3437
                   'bzrlib.tests.per_versionedfile',
3392
3438
                   'bzrlib.tests.per_workingtree',
3393
3439
                   'bzrlib.tests.test__annotator',
3394
3440
                   'bzrlib.tests.test__chk_map',
3422
3468
                   'bzrlib.tests.test_config',
3423
3469
                   'bzrlib.tests.test_conflicts',
3424
3470
                   'bzrlib.tests.test_counted_lock',
 
3471
                   'bzrlib.tests.test_crash',
3425
3472
                   'bzrlib.tests.test_decorators',
3426
3473
                   'bzrlib.tests.test_delta',
3427
3474
                   'bzrlib.tests.test_debug',
3460
3507
                   'bzrlib.tests.test_knit',
3461
3508
                   'bzrlib.tests.test_lazy_import',
3462
3509
                   'bzrlib.tests.test_lazy_regex',
 
3510
                   'bzrlib.tests.test_lock',
3463
3511
                   'bzrlib.tests.test_lockable_files',
3464
3512
                   'bzrlib.tests.test_lockdir',
3465
3513
                   'bzrlib.tests.test_log',
3480
3528
                   'bzrlib.tests.test_osutils',
3481
3529
                   'bzrlib.tests.test_osutils_encodings',
3482
3530
                   'bzrlib.tests.test_pack',
3483
 
                   'bzrlib.tests.test_pack_repository',
3484
3531
                   'bzrlib.tests.test_patch',
3485
3532
                   'bzrlib.tests.test_patches',
3486
3533
                   'bzrlib.tests.test_permissions',
3540
3587
                   'bzrlib.tests.test_urlutils',
3541
3588
                   'bzrlib.tests.test_version',
3542
3589
                   'bzrlib.tests.test_version_info',
3543
 
                   'bzrlib.tests.test_versionedfile',
3544
3590
                   'bzrlib.tests.test_weave',
3545
3591
                   'bzrlib.tests.test_whitebox',
3546
3592
                   'bzrlib.tests.test_win32utils',
3773
3819
    try:
3774
3820
        osutils.rmtree(dirname)
3775
3821
    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
 
3822
        # We don't want to fail here because some useful display will be lost
 
3823
        # otherwise. Polluting the tmp dir is bad, but not giving all the
 
3824
        # possible info to the test runner is even worse.
 
3825
        sys.stderr.write('Unable to remove testing dir %s\n%s'
 
3826
                         % (os.path.basename(dirname), e))
3783
3827
 
3784
3828
 
3785
3829
class Feature(object):