557
557
self.assertEqualDiff(content, open(path, 'r').read())
560
class MetaTestLog(TestCase):
561
def test_logging(self):
562
"""Test logs are captured when a test fails."""
563
self.log('a test message')
564
self._log_file.flush()
565
self.assertContainsRe(self._get_log(), 'a test message\n')
568
560
def filter_suite_by_re(suite, pattern):
569
561
result = TestUtil.TestSuite()
570
562
filter_re = re.compile(pattern)
613
605
global MODULES_TO_DOCTEST
615
# FIXME: If these fail to load, e.g. because of a syntax error, the
616
# exception is hidden by unittest. Sucks. Should either fix that or
617
# perhaps import them and pass them to unittest as modules.
619
['bzrlib.tests.MetaTestLog',
620
608
'bzrlib.tests.test_api',
621
609
'bzrlib.tests.test_gpg',
622
610
'bzrlib.tests.test_identitymap',
665
653
'bzrlib.tests.test_tsort',
666
654
'bzrlib.tests.test_trace',
667
655
'bzrlib.tests.test_rio',
656
'bzrlib.tests.test_selftest',
670
TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
671
print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
659
print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
660
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
673
662
suite = TestSuite()
674
suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
663
# python2.4's TestLoader.loadTestsFromNames gives very poor
664
# errors if it fails to load a named module - no indication of what's
665
# actually wrong, just "no such module". We should probably override that
666
# class, but for the moment just load them ourselves. (mbp 20051202)
667
loader = TestLoader()
668
for mod_name in testmod_names:
669
mod = _load_module_by_name(mod_name)
670
suite.addTest(loader.loadTestsFromModule(mod))
675
671
for package in packages_to_test():
676
672
suite.addTest(package.test_suite())
677
673
for m in MODULES_TO_TEST:
678
suite.addTest(TestLoader().loadTestsFromModule(m))
674
suite.addTest(loader.loadTestsFromModule(m))
679
675
for m in (MODULES_TO_DOCTEST):
680
676
suite.addTest(DocTestSuite(m))
681
677
for p in bzrlib.plugin.all_plugins:
683
679
suite.addTest(p.test_suite())
683
def _load_module_by_name(mod_name):
684
parts = mod_name.split('.')
685
module = __import__(mod_name)
687
# for historical reasons python returns the top-level module even though
688
# it loads the submodule; we need to walk down to get the one we want.
690
module = getattr(module, parts.pop(0))