97
96
# the beginning, but in an id, the important words are
99
98
SHOW_DESCRIPTIONS = False
100
what = SHOW_DESCRIPTIONS and test.shortDescription()
103
what = what[:62] + '...'
106
if what.startswith('bzrlib.tests.'):
109
what = '...' + what[-62:]
111
self.stream.write('%-65.65s' % what)
100
width = bzrlib.osutils.terminal_width()
101
name_width = width - 15
103
if SHOW_DESCRIPTIONS:
104
what = test.shortDescription()
106
if len(what) > name_width:
107
what = what[:name_width-3] + '...'
110
if what.startswith('bzrlib.tests.'):
112
if len(what) > name_width:
113
what = '...' + what[3-name_width:]
114
what = what.ljust(name_width)
115
self.stream.write(what)
112
116
self.stream.flush()
113
117
self._start_time = time.time()
250
254
The file is removed as the test is torn down.
252
256
fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
253
self._log_file = os.fdopen(fileno, 'w+')
257
encoder, decoder, stream_reader, stream_writer = codecs.lookup('UTF-8')
258
self._log_file = stream_writer(os.fdopen(fileno, 'w+'))
254
259
bzrlib.trace.enable_test_log(self._log_file)
255
260
self._log_file_name = name
256
261
self.addCleanup(self._finishLogFile)
546
551
def failUnlessExists(self, path):
547
552
"""Fail unless path, which may be abs or relative, exists."""
548
self.failUnless(osutils.lexists(path))
553
self.failUnless(bzrlib.osutils.lexists(path))
550
555
def assertFileEqual(self, content, path):
551
556
"""Fail if path does not contain 'content'."""
552
self.failUnless(osutils.lexists(path))
557
self.failUnless(bzrlib.osutils.lexists(path))
553
558
self.assertEqualDiff(content, open(path, 'r').read())
556
class MetaTestLog(TestCase):
557
def test_logging(self):
558
"""Test logs are captured when a test fails."""
559
self.log('a test message')
560
self._log_file.flush()
561
self.assertContainsRe(self._get_log(), 'a test message\n')
564
561
def filter_suite_by_re(suite, pattern):
565
result = TestUtil.TestSuite()
566
563
filter_re = re.compile(pattern)
567
564
for test in iter_suite_tests(suite):
568
565
if filter_re.search(test.id()):
609
606
global MODULES_TO_DOCTEST
611
# FIXME: If these fail to load, e.g. because of a syntax error, the
612
# exception is hidden by unittest. Sucks. Should either fix that or
613
# perhaps import them and pass them to unittest as modules.
615
['bzrlib.tests.MetaTestLog',
609
'bzrlib.tests.test_ancestry',
616
610
'bzrlib.tests.test_api',
617
'bzrlib.tests.test_gpg',
618
'bzrlib.tests.test_identitymap',
619
'bzrlib.tests.test_inv',
620
'bzrlib.tests.test_ancestry',
611
'bzrlib.tests.test_bad_files',
612
'bzrlib.tests.test_branch',
621
613
'bzrlib.tests.test_commit',
622
614
'bzrlib.tests.test_command',
623
615
'bzrlib.tests.test_commit_merge',
624
616
'bzrlib.tests.test_config',
617
'bzrlib.tests.test_gpg',
618
'bzrlib.tests.test_graph',
619
'bzrlib.tests.test_hashcache',
620
'bzrlib.tests.test_identitymap',
621
'bzrlib.tests.test_inv',
622
'bzrlib.tests.test_log',
625
623
'bzrlib.tests.test_merge3',
626
624
'bzrlib.tests.test_merge',
627
'bzrlib.tests.test_hashcache',
628
'bzrlib.tests.test_status',
629
'bzrlib.tests.test_log',
625
'bzrlib.tests.test_merge_core',
626
'bzrlib.tests.test_msgeditor',
630
627
'bzrlib.tests.test_revisionnamespaces',
631
'bzrlib.tests.test_branch',
632
628
'bzrlib.tests.test_revision',
633
629
'bzrlib.tests.test_revision_info',
634
'bzrlib.tests.test_merge_core',
630
'bzrlib.tests.test_status',
635
631
'bzrlib.tests.test_smart_add',
636
'bzrlib.tests.test_bad_files',
637
632
'bzrlib.tests.test_diff',
638
633
'bzrlib.tests.test_parent',
639
634
'bzrlib.tests.test_xml',
645
640
'bzrlib.tests.test_transactions',
646
641
'bzrlib.tests.test_transport',
647
642
'bzrlib.tests.test_sftp',
648
'bzrlib.tests.test_graph',
649
643
'bzrlib.tests.test_workingtree',
650
644
'bzrlib.tests.test_upgrade',
651
645
'bzrlib.tests.test_uncommit',
646
'bzrlib.tests.test_ui',
652
647
'bzrlib.tests.test_conflicts',
653
'bzrlib.tests.test_testament',
654
648
'bzrlib.tests.test_annotate',
655
'bzrlib.tests.test_revprops',
656
'bzrlib.tests.test_options',
657
649
'bzrlib.tests.test_http',
658
650
'bzrlib.tests.test_nonascii',
651
'bzrlib.tests.test_options',
652
'bzrlib.tests.test_plugins',
653
'bzrlib.tests.test_revprops',
659
654
'bzrlib.tests.test_reweave',
655
'bzrlib.tests.test_rio',
656
'bzrlib.tests.test_selftest',
657
'bzrlib.tests.test_testament',
658
'bzrlib.tests.test_trace',
660
659
'bzrlib.tests.test_tsort',
661
'bzrlib.tests.test_trace',
662
'bzrlib.tests.test_basicio',
665
TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
666
print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
662
print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
663
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
668
665
suite = TestSuite()
669
suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
666
# python2.4's TestLoader.loadTestsFromNames gives very poor
667
# errors if it fails to load a named module - no indication of what's
668
# actually wrong, just "no such module". We should probably override that
669
# class, but for the moment just load them ourselves. (mbp 20051202)
670
loader = TestLoader()
671
for mod_name in testmod_names:
672
mod = _load_module_by_name(mod_name)
673
suite.addTest(loader.loadTestsFromModule(mod))
670
674
for package in packages_to_test():
671
675
suite.addTest(package.test_suite())
672
676
for m in MODULES_TO_TEST:
673
suite.addTest(TestLoader().loadTestsFromModule(m))
677
suite.addTest(loader.loadTestsFromModule(m))
674
678
for m in (MODULES_TO_DOCTEST):
675
679
suite.addTest(DocTestSuite(m))
676
for p in bzrlib.plugin.all_plugins:
677
if hasattr(p, 'test_suite'):
678
suite.addTest(p.test_suite())
680
for name, plugin in bzrlib.plugin.all_plugins().items():
681
if hasattr(plugin, 'test_suite'):
682
suite.addTest(plugin.test_suite())
686
def _load_module_by_name(mod_name):
687
parts = mod_name.split('.')
688
module = __import__(mod_name)
690
# for historical reasons python returns the top-level module even though
691
# it loads the submodule; we need to walk down to get the one we want.
693
module = getattr(module, parts.pop(0))