850
853
ui.ui_factory = ui.SilentUIFactory()
851
854
self.addCleanup(_restore)
856
def _check_locks(self):
857
"""Check that all lock take/release actions have been paired."""
858
# once we have fixed all the current lock problems, we can change the
859
# following code to always check for mismatched locks, but only do
860
# traceback showing with -Dlock (self._lock_check_thorough is True).
861
# For now, because the test suite will fail, we only assert that lock
862
# matching has occured with -Dlock.
864
acquired_locks = [lock for action, lock in self._lock_actions
865
if action == 'acquired']
866
released_locks = [lock for action, lock in self._lock_actions
867
if action == 'released']
868
# trivially, given the tests for lock acquistion and release, if we
869
# have as many in each list, it should be ok.
870
if len(acquired_locks) != len(released_locks):
872
("Different number of acquired and released locks. (%s, %s)" %
873
(acquired_locks, released_locks))
874
if not self._lock_check_thorough:
875
# Rather than fail, just warn
876
print "Broken test %s: %s" % (self, message)
880
def _track_locks(self):
881
"""Track lock activity during tests."""
882
self._lock_actions = []
883
self._lock_check_thorough = 'lock' in debug.debug_flags
884
self.addCleanup(self._check_locks)
885
_mod_lock.Lock.hooks.install_named_hook('lock_acquired', self._lock_acquired, None)
886
_mod_lock.Lock.hooks.install_named_hook('lock_released', self._lock_released, None)
888
def _lock_acquired(self, result):
889
self._lock_actions.append(('acquired', result))
891
def _lock_released(self, result):
892
self._lock_actions.append(('released', result))
853
894
def _ndiff_strings(self, a, b):
854
895
"""Return ndiff between two strings containing lines.
1350
1391
"test setUp did not invoke "
1351
1392
"bzrlib.tests.TestCase's setUp")
1352
1393
except KeyboardInterrupt:
1354
1396
except TestSkipped, e:
1355
1397
self._do_skip(result, e.args[0])
1356
1398
self.tearDown()
1359
1401
result.addError(self, sys.exc_info())
1383
1427
"test tearDown did not invoke "
1384
1428
"bzrlib.tests.TestCase's tearDown")
1385
1429
except KeyboardInterrupt:
1388
1433
result.addError(self, sys.exc_info())
1390
1436
if ok: result.addSuccess(self)
1392
1438
result.stopTest(self)
1394
1440
except TestNotApplicable:
1395
1441
# Not moved from the result [yet].
1397
1444
except KeyboardInterrupt:
1400
1448
saved_attrs = {}
1406
1454
self.__dict__ = saved_attrs
1408
1456
def tearDown(self):
1409
self._bzr_test_tearDown_run = True
1410
1457
self._runCleanups()
1411
1458
self._log_contents = ''
1459
self._bzr_test_tearDown_run = True
1412
1460
unittest.TestCase.tearDown(self)
1414
1462
def time(self, callable, *args, **kwargs):