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',
666
654
'bzrlib.tests.test_trace',
667
655
'bzrlib.tests.test_rio',
668
656
'bzrlib.tests.test_msgeditor',
657
'bzrlib.tests.test_selftest',
671
TestCase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
672
print '%-30s %s' % ('bzr binary', TestCase.BZRPATH)
660
print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
661
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
674
663
suite = TestSuite()
675
suite.addTest(TestLoader().loadTestsFromNames(testmod_names))
664
# python2.4's TestLoader.loadTestsFromNames gives very poor
665
# errors if it fails to load a named module - no indication of what's
666
# actually wrong, just "no such module". We should probably override that
667
# class, but for the moment just load them ourselves. (mbp 20051202)
668
loader = TestLoader()
669
for mod_name in testmod_names:
670
mod = _load_module_by_name(mod_name)
671
suite.addTest(loader.loadTestsFromModule(mod))
676
672
for package in packages_to_test():
677
673
suite.addTest(package.test_suite())
678
674
for m in MODULES_TO_TEST:
679
suite.addTest(TestLoader().loadTestsFromModule(m))
675
suite.addTest(loader.loadTestsFromModule(m))
680
676
for m in (MODULES_TO_DOCTEST):
681
677
suite.addTest(DocTestSuite(m))
682
678
for p in bzrlib.plugin.all_plugins:
684
680
suite.addTest(p.test_suite())
684
def _load_module_by_name(mod_name):
685
parts = mod_name.split('.')
686
module = __import__(mod_name)
688
# for historical reasons python returns the top-level module even though
689
# it loads the submodule; we need to walk down to get the one we want.
691
module = getattr(module, parts.pop(0))