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)
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',
3481
3504
'bzrlib.tests.test_transactions',
3482
3505
'bzrlib.tests.test_transform',
3483
3506
'bzrlib.tests.test_transport',
3484
'bzrlib.tests.test_transport_implementations',
3485
3507
'bzrlib.tests.test_transport_log',
3486
3508
'bzrlib.tests.test_tree',
3487
3509
'bzrlib.tests.test_treebuilder',
3502
3524
'bzrlib.tests.test_workingtree_4',
3503
3525
'bzrlib.tests.test_wsgi',
3504
3526
'bzrlib.tests.test_xml',
3505
'bzrlib.tests.tree_implementations',
3506
'bzrlib.tests.workingtree_implementations',
3509
3529
loader = TestUtil.TestLoader()
3980
4000
# Only define SubUnitBzrRunner if subunit is available.
3982
4002
from subunit import TestProtocolClient
4004
from subunit.test_results import AutoTimingTestResultDecorator
4006
AutoTimingTestResultDecorator = lambda x:x
3983
4007
class SubUnitBzrRunner(TextTestRunner):
3984
4008
def run(self, test):
3985
result = TestProtocolClient(self.stream)
4009
result = AutoTimingTestResultDecorator(
4010
TestProtocolClient(self.stream))
3986
4011
test.run(result)
3988
4013
except ImportError: