/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: Robert Collins
  • Date: 2009-08-18 02:19:38 UTC
  • mfrom: (4622 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4623.
  • Revision ID: robertc@robertcollins.net-20090818021938-l32d8whr7tjuqjoh
Merge trunk to fixup inventory API change.

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."""
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
 
3461
3505
                   'bzrlib.tests.test_knit',
3462
3506
                   'bzrlib.tests.test_lazy_import',
3463
3507
                   'bzrlib.tests.test_lazy_regex',
 
3508
                   'bzrlib.tests.test_lock',
3464
3509
                   'bzrlib.tests.test_lockable_files',
3465
3510
                   'bzrlib.tests.test_lockdir',
3466
3511
                   'bzrlib.tests.test_log',