104
105
from bzrlib.tests.treeshape import build_tree_contents
106
from bzrlib.ui import NullProgressView
105
107
from bzrlib.ui.text import TextUIFactory
106
108
import bzrlib.version_info_formats.format_custom
107
109
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
114
116
default_transport = LocalURLServer
118
# Subunit result codes, defined here to prevent a hard dependency on subunit.
117
123
class ExtendedTestResult(unittest._TextTestResult):
118
124
"""Accepts, reports and accumulates the results of running tests.
159
164
bench_history.write("--date %s %s\n" % (time.time(), revision_id))
160
165
self._bench_history = bench_history
161
166
self.ui = ui.ui_factory
162
self.num_tests = num_tests
163
168
self.error_count = 0
164
169
self.failure_count = 0
165
170
self.known_failure_count = 0
220
227
self._recordTestStartTime()
222
229
def startTests(self):
224
'testing: %s\n' % (osutils.realpath(sys.argv[0]),))
226
' %s (%s python%s)\n' % (
231
if getattr(sys, 'frozen', None) is None:
232
bzr_path = osutils.realpath(sys.argv[0])
234
bzr_path = sys.executable
236
'testing: %s\n' % (bzr_path,))
239
bzrlib.__path__[0],))
241
' bzr-%s python-%s %s\n' % (
228
242
bzrlib.version_string,
229
243
bzrlib._format_version_tuple(sys.version_info),
244
platform.platform(aliased=1),
231
246
self.stream.write('\n')
359
374
self.stream.writeln(self.separator2)
360
375
self.stream.writeln("%s" % err)
377
def progress(self, offset, whence):
378
"""The test is adjusting the count of tests to run."""
379
if whence == SUBUNIT_SEEK_SET:
380
self.num_tests = offset
381
elif whence == SUBUNIT_SEEK_CUR:
382
self.num_tests += offset
384
raise errors.BzrError("Unknown whence %r" % whence)
362
386
def finished(self):
380
404
def __init__(self, stream, descriptions, verbosity,
381
405
bench_history=None,
386
409
ExtendedTestResult.__init__(self, stream, descriptions, verbosity,
387
bench_history, num_tests, strict)
389
self.pb = self.ui.nested_progress_bar()
390
self._supplied_pb = False
393
self._supplied_pb = True
410
bench_history, strict)
411
# We no longer pass them around, but just rely on the UIFactory stack
414
warnings.warn("Passing pb to TextTestResult is deprecated")
415
self.pb = self.ui.nested_progress_bar()
394
416
self.pb.show_pct = False
395
417
self.pb.show_spinner = False
396
418
self.pb.show_eta = False,
397
419
self.pb.show_count = False
398
420
self.pb.show_bar = False
421
self.pb.update_latency = 0
422
self.pb.show_transport_activity = False
425
# called when the tests that are going to run have run
427
super(TextTestResult, self).done()
400
432
def report_starting(self):
401
433
self.pb.update('[test 0/%d] Starting' % (self.num_tests))
435
def printErrors(self):
436
# clear the pb to make room for the error listing
438
super(TextTestResult, self).printErrors()
403
440
def _progress_prefix_text(self):
404
441
# the longer this text, the less space we have to show the test
410
447
## a += ', %d skip' % self.skip_count
411
448
## if self.known_failure_count:
412
449
## a += '+%dX' % self.known_failure_count
413
if self.num_tests is not None:
414
451
a +='/%d' % self.num_tests
416
453
runtime = time.time() - self._overall_start_time
465
502
def report_cleaning_up(self):
466
503
self.pb.update('Cleaning up')
469
if not self._supplied_pb:
473
506
class VerboseTestResult(ExtendedTestResult):
474
507
"""Produce long output, with one line per test run plus times"""
709
741
Hide the progress bar but emit note()s.
711
743
Allows get_password to be tested without real tty attached.
745
See also CannedInputUIFactory which lets you provide programmatic input in
748
# TODO: Capture progress events at the model level and allow them to be
749
# observed by tests that care.
751
# XXX: Should probably unify more with CannedInputUIFactory or a
752
# particular configuration of TextUIFactory, or otherwise have a clearer
753
# idea of how they're supposed to be different.
754
# See https://bugs.edge.launchpad.net/bzr/+bug/408213
714
756
def __init__(self, stdout=None, stderr=None, stdin=None):
715
757
if stdin is not None:
720
762
stdin = StringIOWrapper(stdin)
721
763
super(TestUIFactory, self).__init__(stdin, stdout, stderr)
724
"""See progress.ProgressBar.clear()."""
726
def clear_term(self):
727
"""See progress.ProgressBar.clear_term()."""
730
"""See progress.ProgressBar.finished()."""
732
def note(self, fmt_string, *args):
733
"""See progress.ProgressBar.note()."""
735
fmt_string = fmt_string % args
736
self.stdout.write(fmt_string + "\n")
738
def progress_bar(self):
741
def nested_progress_bar(self):
744
def update(self, message, count=None, total=None):
745
"""See progress.ProgressBar.update()."""
747
765
def get_non_echoed_password(self):
748
766
"""Get password from stdin without trying to handle the echo mode"""
749
767
password = self.stdin.readline()
831
851
self._preserved_debug_flags = set(debug.debug_flags)
832
852
if 'allow_debug' not in selftest_debug_flags:
833
853
debug.debug_flags.clear()
854
if 'disable_lock_checks' not in selftest_debug_flags:
855
debug.debug_flags.add('strict_locks')
834
856
self.addCleanup(self._restore_debug_flags)
836
858
def _clear_hooks(self):
859
881
def _check_locks(self):
860
882
"""Check that all lock take/release actions have been paired."""
861
# once we have fixed all the current lock problems, we can change the
862
# following code to always check for mismatched locks, but only do
863
# traceback showing with -Dlock (self._lock_check_thorough is True).
864
# For now, because the test suite will fail, we only assert that lock
865
# matching has occured with -Dlock.
883
# We always check for mismatched locks. If a mismatch is found, we
884
# fail unless -Edisable_lock_checks is supplied to selftest, in which
885
# case we just print a warning.
867
887
acquired_locks = [lock for action, lock in self._lock_actions
868
888
if action == 'acquired']
887
907
def _track_locks(self):
888
908
"""Track lock activity during tests."""
889
909
self._lock_actions = []
890
self._lock_check_thorough = 'lock' not in debug.debug_flags
910
if 'disable_lock_checks' in selftest_debug_flags:
911
self._lock_check_thorough = False
913
self._lock_check_thorough = True
891
915
self.addCleanup(self._check_locks)
892
916
_mod_lock.Lock.hooks.install_named_hook('lock_acquired',
893
917
self._lock_acquired, None)
1309
1333
"""Make the logfile not be deleted when _finishLogFile is called."""
1310
1334
self._keep_log_file = True
1336
def thisFailsStrictLockCheck(self):
1337
"""It is known that this test would fail with -Dstrict_locks.
1339
By default, all tests are run with strict lock checking unless
1340
-Edisable_lock_checks is supplied. However there are some tests which
1341
we know fail strict locks at this point that have not been fixed.
1342
They should call this function to disable the strict checking.
1344
This should be used sparingly, it is much better to fix the locking
1345
issues rather than papering over the problem by calling this function.
1347
debug.debug_flags.discard('strict_locks')
1312
1349
def addCleanup(self, callable, *args, **kwargs):
1313
1350
"""Arrange to run a callable when this case is torn down.
1582
1619
def _run_bzr_core(self, args, retcode, encoding, stdin,
1621
# Clear chk_map page cache, because the contents are likely to mask
1623
chk_map.clear_cache()
1584
1624
if encoding is None:
1585
1625
encoding = osutils.get_user_encoding()
1586
1626
stdout = StringIOWrapper()
1926
1966
sio.encoding = output_encoding
1969
def disable_verb(self, verb):
1970
"""Disable a smart server verb for one test."""
1971
from bzrlib.smart import request
1972
request_handlers = request.request_handlers
1973
orig_method = request_handlers.get(verb)
1974
request_handlers.remove(verb)
1976
request_handlers.register(verb, orig_method)
1977
self.addCleanup(restoreVerb)
1930
1980
class CapturedCall(object):
1931
1981
"""A helper for capturing smart server calls for easy debug analysis."""
2299
2349
def _getTestDirPrefix(self):
2300
2350
# create a directory within the top level test directory
2301
if sys.platform == 'win32':
2351
if sys.platform in ('win32', 'cygwin'):
2302
2352
name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
2303
2353
# windows is likely to have path-length limits so use a short name
2304
2354
name_prefix = name_prefix[-30:]
2752
2802
decorators.append(filter_tests(pattern))
2753
2803
if suite_decorators:
2754
2804
decorators.extend(suite_decorators)
2805
# tell the result object how many tests will be running: (except if
2806
# --parallel=fork is being used. Robert said he will provide a better
2807
# progress design later -- vila 20090817)
2808
if fork_decorator not in decorators:
2809
decorators.append(CountingDecorator)
2755
2810
for decorator in decorators:
2756
2811
suite = decorator(suite)
2757
2812
result = runner.run(suite)
2919
class CountingDecorator(TestDecorator):
2920
"""A decorator which calls result.progress(self.countTestCases)."""
2922
def run(self, result):
2923
progress_method = getattr(result, 'progress', None)
2924
if callable(progress_method):
2925
progress_method(self.countTestCases(), SUBUNIT_SEEK_SET)
2926
return super(CountingDecorator, self).run(result)
2864
2929
class ExcludeDecorator(TestDecorator):
2865
2930
"""A decorator which excludes test matching an exclude pattern."""
3123
3188
# Controlled by "bzr selftest -E=..." option
3189
# Currently supported:
3190
# -Eallow_debug Will no longer clear debug.debug_flags() so it
3191
# preserves any flags supplied at the command line.
3192
# -Edisable_lock_checks Turns errors in mismatched locks into simple prints
3193
# rather than failing tests. And no longer raise
3194
# LockContention when fctnl locks are not being used
3195
# with proper exclusion rules.
3124
3196
selftest_debug_flags = set()
3161
3234
keep_only = None
3163
3236
keep_only = load_test_id_list(load_list)
3238
starting_with = [test_prefix_alias_registry.resolve_alias(start)
3239
for start in starting_with]
3164
3240
if test_suite_factory is None:
3241
# Reduce loading time by loading modules based on the starting_with
3165
3243
suite = test_suite(keep_only, starting_with)
3167
3245
suite = test_suite_factory()
3247
# But always filter as requested.
3248
suite = filter_suite_by_id_startswith(suite, starting_with)
3168
3249
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
3169
3250
stop_on_failure=stop_on_failure,
3170
3251
transport=transport,
3362
3444
'bzrlib.tests.per_lock',
3363
3445
'bzrlib.tests.per_transport',
3364
3446
'bzrlib.tests.per_tree',
3447
'bzrlib.tests.per_pack_repository',
3365
3448
'bzrlib.tests.per_repository',
3366
3449
'bzrlib.tests.per_repository_chk',
3367
3450
'bzrlib.tests.per_repository_reference',
3451
'bzrlib.tests.per_versionedfile',
3368
3452
'bzrlib.tests.per_workingtree',
3369
3453
'bzrlib.tests.test__annotator',
3370
3454
'bzrlib.tests.test__chk_map',
3398
3482
'bzrlib.tests.test_config',
3399
3483
'bzrlib.tests.test_conflicts',
3400
3484
'bzrlib.tests.test_counted_lock',
3485
'bzrlib.tests.test_crash',
3401
3486
'bzrlib.tests.test_decorators',
3402
3487
'bzrlib.tests.test_delta',
3403
3488
'bzrlib.tests.test_debug',
3436
3521
'bzrlib.tests.test_knit',
3437
3522
'bzrlib.tests.test_lazy_import',
3438
3523
'bzrlib.tests.test_lazy_regex',
3524
'bzrlib.tests.test_lock',
3439
3525
'bzrlib.tests.test_lockable_files',
3440
3526
'bzrlib.tests.test_lockdir',
3441
3527
'bzrlib.tests.test_log',
3456
3542
'bzrlib.tests.test_osutils',
3457
3543
'bzrlib.tests.test_osutils_encodings',
3458
3544
'bzrlib.tests.test_pack',
3459
'bzrlib.tests.test_pack_repository',
3460
3545
'bzrlib.tests.test_patch',
3461
3546
'bzrlib.tests.test_patches',
3462
3547
'bzrlib.tests.test_permissions',
3516
3601
'bzrlib.tests.test_urlutils',
3517
3602
'bzrlib.tests.test_version',
3518
3603
'bzrlib.tests.test_version_info',
3519
'bzrlib.tests.test_versionedfile',
3520
3604
'bzrlib.tests.test_weave',
3521
3605
'bzrlib.tests.test_whitebox',
3522
3606
'bzrlib.tests.test_win32utils',
3531
3615
if keep_only is not None:
3532
3616
id_filter = TestIdList(keep_only)
3533
3617
if starting_with:
3534
starting_with = [test_prefix_alias_registry.resolve_alias(start)
3535
for start in starting_with]
3536
3618
# We take precedence over keep_only because *at loading time* using
3537
3619
# both options means we will load less tests for the same final result.
3538
3620
def interesting_module(name):
3614
3696
sys.setdefaultencoding(default_encoding)
3617
suite = filter_suite_by_id_startswith(suite, starting_with)
3619
3698
if keep_only is not None:
3620
3699
# Now that the referred modules have loaded their tests, keep only the
3621
3700
# requested ones.
3750
3829
osutils.rmtree(dirname)
3751
3830
except OSError, e:
3752
if sys.platform == 'win32' and e.errno == errno.EACCES:
3753
sys.stderr.write('Permission denied: '
3754
'unable to remove testing dir '
3756
% (os.path.basename(dirname), e))
3831
# We don't want to fail here because some useful display will be lost
3832
# otherwise. Polluting the tmp dir is bad, but not giving all the
3833
# possible info to the test runner is even worse.
3834
sys.stderr.write('Unable to remove testing dir %s\n%s'
3835
% (os.path.basename(dirname), e))
3761
3838
class Feature(object):