727
728
def finished(self):
728
729
"""See progress.ProgressBar.finished()."""
730
def note(self, fmt_string, *args, **kwargs):
731
def note(self, fmt_string, *args):
731
732
"""See progress.ProgressBar.note()."""
732
self.stdout.write((fmt_string + "\n") % args)
734
fmt_string = fmt_string % args
735
self.stdout.write(fmt_string + "\n")
734
737
def progress_bar(self):
781
784
_gather_lsprof_in_benchmarks = False
782
785
attrs_to_keep = ('id', '_testMethodName', '_testMethodDoc',
783
786
'_log_contents', '_log_file_name', '_benchtime',
784
'_TestCase__testMethodName')
787
'_TestCase__testMethodName', '_TestCase__testMethodDoc',)
786
789
def __init__(self, methodName='testMethod'):
787
790
super(TestCase, self).__init__(methodName)
850
855
ui.ui_factory = ui.SilentUIFactory()
851
856
self.addCleanup(_restore)
858
def _check_locks(self):
859
"""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.
866
acquired_locks = [lock for action, lock in self._lock_actions
867
if action == 'acquired']
868
released_locks = [lock for action, lock in self._lock_actions
869
if action == 'released']
870
broken_locks = [lock for action, lock in self._lock_actions
871
if action == 'broken']
872
# trivially, given the tests for lock acquistion and release, if we
873
# have as many in each list, it should be ok. Some lock tests also
874
# break some locks on purpose and should be taken into account by
875
# considering that breaking a lock is just a dirty way of releasing it.
876
if len(acquired_locks) != (len(released_locks) + len(broken_locks)):
877
message = ('Different number of acquired and '
878
'released or broken locks. (%s, %s + %s)' %
879
(acquired_locks, released_locks, broken_locks))
880
if not self._lock_check_thorough:
881
# Rather than fail, just warn
882
print "Broken test %s: %s" % (self, message)
886
def _track_locks(self):
887
"""Track lock activity during tests."""
888
self._lock_actions = []
889
self._lock_check_thorough = 'lock' not in debug.debug_flags
890
self.addCleanup(self._check_locks)
891
_mod_lock.Lock.hooks.install_named_hook('lock_acquired',
892
self._lock_acquired, None)
893
_mod_lock.Lock.hooks.install_named_hook('lock_released',
894
self._lock_released, None)
895
_mod_lock.Lock.hooks.install_named_hook('lock_broken',
896
self._lock_broken, None)
898
def _lock_acquired(self, result):
899
self._lock_actions.append(('acquired', result))
901
def _lock_released(self, result):
902
self._lock_actions.append(('released', result))
904
def _lock_broken(self, result):
905
self._lock_actions.append(('broken', result))
853
907
def _ndiff_strings(self, a, b):
854
908
"""Return ndiff between two strings containing lines.
1383
1440
"test tearDown did not invoke "
1384
1441
"bzrlib.tests.TestCase's tearDown")
1385
1442
except KeyboardInterrupt:
1388
1446
result.addError(self, sys.exc_info())
1390
1449
if ok: result.addSuccess(self)
1392
1451
result.stopTest(self)
1394
1453
except TestNotApplicable:
1395
1454
# Not moved from the result [yet].
1397
1457
except KeyboardInterrupt:
1400
1461
saved_attrs = {}
1401
absent_attr = object()
1402
1462
for attr_name in self.attrs_to_keep:
1403
attr = getattr(self, attr_name, absent_attr)
1404
if attr is not absent_attr:
1405
saved_attrs[attr_name] = attr
1463
if attr_name in self.__dict__:
1464
saved_attrs[attr_name] = self.__dict__[attr_name]
1406
1465
self.__dict__ = saved_attrs
1408
1467
def tearDown(self):
1409
self._bzr_test_tearDown_run = True
1410
1468
self._runCleanups()
1411
1469
self._log_contents = ''
1470
self._bzr_test_tearDown_run = True
1412
1471
unittest.TestCase.tearDown(self)
1414
1473
def time(self, callable, *args, **kwargs):
2994
def cpucount(content):
2995
lines = content.splitlines()
2996
prefix = 'processor'
2998
if line.startswith(prefix):
2999
concurrency = int(line[line.find(':')+1:]) + 1
3003
def local_concurrency():
3005
content = file('/proc/cpuinfo', 'rb').read()
3006
concurrency = cpucount(content)
3007
except Exception, e:
3012
3054
class BZRTransformingResult(unittest.TestResult):
3014
3056
def __init__(self, target):
3305
3347
'bzrlib.tests.test__chk_map',
3306
3348
'bzrlib.tests.test__dirstate_helpers',
3307
3349
'bzrlib.tests.test__groupcompress',
3350
'bzrlib.tests.test__known_graph',
3351
'bzrlib.tests.test__rio',
3308
3352
'bzrlib.tests.test__walkdirs_win32',
3309
3353
'bzrlib.tests.test_ancestry',
3310
3354
'bzrlib.tests.test_annotate',
3311
3355
'bzrlib.tests.test_api',
3312
3356
'bzrlib.tests.test_atomicfile',
3313
3357
'bzrlib.tests.test_bad_files',
3358
'bzrlib.tests.test_bencode',
3314
3359
'bzrlib.tests.test_bisect_multi',
3315
3360
'bzrlib.tests.test_branch',
3316
3361
'bzrlib.tests.test_branchbuilder',
3321
3366
'bzrlib.tests.test__chunks_to_lines',
3322
3367
'bzrlib.tests.test_cache_utf8',
3323
3368
'bzrlib.tests.test_chk_map',
3369
'bzrlib.tests.test_chk_serializer',
3324
3370
'bzrlib.tests.test_chunk_writer',
3325
3371
'bzrlib.tests.test_clean_tree',
3326
3372
'bzrlib.tests.test_commands',
3356
3402
'bzrlib.tests.test_help',
3357
3403
'bzrlib.tests.test_hooks',
3358
3404
'bzrlib.tests.test_http',
3359
'bzrlib.tests.test_http_implementations',
3360
3405
'bzrlib.tests.test_http_response',
3361
3406
'bzrlib.tests.test_https_ca_bundle',
3362
3407
'bzrlib.tests.test_identitymap',