104
104
from bzrlib.tests.treeshape import build_tree_contents
105
from bzrlib.ui.text import TextUIFactory
105
106
import bzrlib.version_info_formats.format_custom
106
107
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
195
196
def _testTimeString(self, testCase):
196
197
benchmark_time = self._extractBenchmarkTime(testCase)
197
198
if benchmark_time is not None:
199
self._formatTime(benchmark_time),
200
self._elapsedTestTimeString())
199
return self._formatTime(benchmark_time) + "*"
202
return " %s" % self._elapsedTestTimeString()
201
return self._elapsedTestTimeString()
204
203
def _formatTime(self, seconds):
205
204
"""Format seconds as milliseconds with leading spaces."""
346
345
self.stream.write("%s: " % flavour)
347
346
self.stream.writeln(self.getDescription(test))
348
347
if getattr(test, '_get_log', None) is not None:
349
self.stream.write('\n')
351
('vvvv[log from %s]' % test.id()).ljust(78,'-'))
352
self.stream.write('\n')
353
self.stream.write(test._get_log())
354
self.stream.write('\n')
356
('^^^^[log from %s]' % test.id()).ljust(78,'-'))
357
self.stream.write('\n')
348
log_contents = test._get_log()
350
self.stream.write('\n')
352
('vvvv[log from %s]' % test.id()).ljust(78,'-'))
353
self.stream.write('\n')
354
self.stream.write(log_contents)
355
self.stream.write('\n')
357
('^^^^[log from %s]' % test.id()).ljust(78,'-'))
358
self.stream.write('\n')
358
359
self.stream.writeln(self.separator2)
359
360
self.stream.writeln("%s" % err)
486
487
def report_test_start(self, test):
488
489
name = self._shortened_test_description(test)
489
# width needs space for 6 char status, plus 1 for slash, plus 2 10-char
490
# numbers, plus a trailing blank
490
# width needs space for 6 char status, plus 1 for slash, plus an
491
# 11-char time string, plus a trailing blank
491
492
# when NUMBERED_DIRS: plus 5 chars on test number, plus 1 char on space
492
493
self.stream.write(self._ellipsize_to_right(name,
493
osutils.terminal_width()-30))
494
osutils.terminal_width()-18))
494
495
self.stream.flush()
496
497
def _error_summary(self, err):
702
703
return setattr(self._cstring, name, val)
705
class TestUIFactory(ui.CLIUIFactory):
706
class TestUIFactory(TextUIFactory):
706
707
"""A UI Factory for testing.
708
709
Hide the progress bar but emit note()s.
1093
1094
osutils.realpath(path2),
1094
1095
"apparent paths:\na = %s\nb = %s\n," % (path1, path2))
1096
def assertIsInstance(self, obj, kls):
1097
"""Fail if obj is not an instance of kls"""
1097
def assertIsInstance(self, obj, kls, msg=None):
1098
"""Fail if obj is not an instance of kls
1100
:param msg: Supplementary message to show if the assertion fails.
1098
1102
if not isinstance(obj, kls):
1099
self.fail("%r is an instance of %s rather than %s" % (
1100
obj, obj.__class__, kls))
1103
m = "%r is an instance of %s rather than %s" % (
1104
obj, obj.__class__, kls)
1102
1109
def expectFailure(self, reason, assertion, *args, **kwargs):
1103
1110
"""Invoke a test, expecting it to fail for the given reason.
1325
1332
'BZR_PROGRESS_BAR': None,
1326
1333
'BZR_LOG': None,
1327
1334
'BZR_PLUGIN_PATH': None,
1335
# Make sure that any text ui tests are consistent regardless of
1336
# the environment the test case is run in; you may want tests that
1337
# test other combinations. 'dumb' is a reasonable guess for tests
1338
# going to a pipe or a StringIO.
1329
1343
'SSH_AUTH_SOCK': None,
2959
2973
concurrency = osutils.local_concurrency()
2961
2975
from subunit import TestProtocolClient, ProtocolTestCase
2977
from subunit.test_results import AutoTimingTestResultDecorator
2979
AutoTimingTestResultDecorator = lambda x:x
2962
2980
class TestInOtherProcess(ProtocolTestCase):
2963
2981
# Should be in subunit, I think. RBC.
2964
2982
def __init__(self, stream, pid):
2987
3005
sys.stdin.close()
2988
3006
sys.stdin = None
2989
3007
stream = os.fdopen(c2pwrite, 'wb', 1)
2990
subunit_result = TestProtocolClient(stream)
3008
subunit_result = AutoTimingTestResultDecorator(
3009
TestProtocolClient(stream))
2991
3010
process_suite.run(subunit_result)
3008
3027
concurrency = osutils.local_concurrency()
3010
from subunit import TestProtocolClient, ProtocolTestCase
3029
from subunit import ProtocolTestCase
3011
3030
class TestInSubprocess(ProtocolTestCase):
3012
3031
def __init__(self, process, name):
3013
3032
ProtocolTestCase.__init__(self, process.stdout)
3333
3352
testmod_names = [
3335
3354
'bzrlib.tests.blackbox',
3336
'bzrlib.tests.branch_implementations',
3337
'bzrlib.tests.bzrdir_implementations',
3338
3355
'bzrlib.tests.commands',
3339
'bzrlib.tests.interrepository_implementations',
3340
'bzrlib.tests.intertree_implementations',
3341
'bzrlib.tests.inventory_implementations',
3356
'bzrlib.tests.per_branch',
3357
'bzrlib.tests.per_bzrdir',
3358
'bzrlib.tests.per_interrepository',
3359
'bzrlib.tests.per_intertree',
3360
'bzrlib.tests.per_inventory',
3342
3361
'bzrlib.tests.per_interbranch',
3343
3362
'bzrlib.tests.per_lock',
3363
'bzrlib.tests.per_transport',
3364
'bzrlib.tests.per_tree',
3344
3365
'bzrlib.tests.per_repository',
3345
3366
'bzrlib.tests.per_repository_chk',
3346
3367
'bzrlib.tests.per_repository_reference',
3368
'bzrlib.tests.per_workingtree',
3369
'bzrlib.tests.test__annotator',
3347
3370
'bzrlib.tests.test__chk_map',
3348
3371
'bzrlib.tests.test__dirstate_helpers',
3349
3372
'bzrlib.tests.test__groupcompress',
3373
'bzrlib.tests.test__known_graph',
3350
3374
'bzrlib.tests.test__rio',
3351
3375
'bzrlib.tests.test__walkdirs_win32',
3352
3376
'bzrlib.tests.test_ancestry',
3480
3504
'bzrlib.tests.test_transactions',
3481
3505
'bzrlib.tests.test_transform',
3482
3506
'bzrlib.tests.test_transport',
3483
'bzrlib.tests.test_transport_implementations',
3484
3507
'bzrlib.tests.test_transport_log',
3485
3508
'bzrlib.tests.test_tree',
3486
3509
'bzrlib.tests.test_treebuilder',
3501
3524
'bzrlib.tests.test_workingtree_4',
3502
3525
'bzrlib.tests.test_wsgi',
3503
3526
'bzrlib.tests.test_xml',
3504
'bzrlib.tests.tree_implementations',
3505
'bzrlib.tests.workingtree_implementations',
3508
3529
loader = TestUtil.TestLoader()
3531
if keep_only is not None:
3532
id_filter = TestIdList(keep_only)
3510
3533
if starting_with:
3511
3534
starting_with = [test_prefix_alias_registry.resolve_alias(start)
3512
3535
for start in starting_with]
3525
3548
loader = TestUtil.FilteredByModuleTestLoader(interesting_module)
3527
3550
elif keep_only is not None:
3528
id_filter = TestIdList(keep_only)
3529
3551
loader = TestUtil.FilteredByModuleTestLoader(id_filter.refers_to)
3530
3552
def interesting_module(name):
3531
3553
return id_filter.refers_to(name)
3978
4000
# Only define SubUnitBzrRunner if subunit is available.
3980
4002
from subunit import TestProtocolClient
4004
from subunit.test_results import AutoTimingTestResultDecorator
4006
AutoTimingTestResultDecorator = lambda x:x
3981
4007
class SubUnitBzrRunner(TextTestRunner):
3982
4008
def run(self, test):
3983
result = TestProtocolClient(self.stream)
4009
result = AutoTimingTestResultDecorator(
4010
TestProtocolClient(self.stream))
3984
4011
test.run(result)
3986
4013
except ImportError: