1
1
# Copyright (C) 2005, 2006 by Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44
46
import bzrlib.branch
45
47
import bzrlib.bzrdir as bzrdir
46
48
import bzrlib.commands
49
import bzrlib.bundle.serializer
47
50
import bzrlib.errors as errors
48
51
import bzrlib.inventory
49
52
import bzrlib.iterablefile
50
53
import bzrlib.lockdir
57
# lsprof not available
51
59
from bzrlib.merge import merge_inner
52
60
import bzrlib.merge3
53
61
import bzrlib.osutils
54
62
import bzrlib.osutils as osutils
55
63
import bzrlib.plugin
64
import bzrlib.progress as progress
56
65
from bzrlib.revision import common_ancestor
57
66
import bzrlib.store
58
67
import bzrlib.trace
59
from bzrlib.transport import urlescape, get_transport
68
from bzrlib.transport import get_transport
60
69
import bzrlib.transport
61
70
from bzrlib.transport.local import LocalRelpathServer
62
71
from bzrlib.transport.readonly import ReadonlyServer
63
72
from bzrlib.trace import mutter
64
from bzrlib.tests.TestUtil import TestLoader, TestSuite
73
from bzrlib.tests import TestUtil
74
from bzrlib.tests.TestUtil import (
65
78
from bzrlib.tests.treeshape import build_tree_contents
79
import bzrlib.urlutils as urlutils
66
80
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
68
82
default_transport = LocalRelpathServer
114
135
Shows output in a different format, including displaying runtime for tests.
116
137
stop_early = False
118
def _elapsedTime(self):
119
return "%5dms" % (1000 * (time.time() - self._start_time))
139
def __init__(self, stream, descriptions, verbosity, pb=None):
140
unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
143
def extractBenchmarkTime(self, testCase):
144
"""Add a benchmark time for the current test case."""
145
self._benchmarkTime = getattr(testCase, "_benchtime", None)
147
def _elapsedTestTimeString(self):
148
"""Return a time string for the overall time the current test has taken."""
149
return self._formatTime(time.time() - self._start_time)
151
def _testTimeString(self):
152
if self._benchmarkTime is not None:
154
self._formatTime(self._benchmarkTime),
155
self._elapsedTestTimeString())
157
return " %s" % self._elapsedTestTimeString()
159
def _formatTime(self, seconds):
160
"""Format seconds as milliseconds with leading spaces."""
161
return "%5dms" % (1000 * seconds)
163
def _ellipsise_unimportant_words(self, a_string, final_width,
165
"""Add ellipses (sp?) for overly long strings.
167
:param keep_start: If true preserve the start of a_string rather
171
if len(a_string) > final_width:
172
result = a_string[:final_width-3] + '...'
176
if len(a_string) > final_width:
177
result = '...' + a_string[3-final_width:]
180
return result.ljust(final_width)
121
182
def startTest(self, test):
122
183
unittest.TestResult.startTest(self, test)
124
185
# the beginning, but in an id, the important words are
126
187
SHOW_DESCRIPTIONS = False
189
if not self.showAll and self.dots and self.pb is not None:
192
final_width = osutils.terminal_width()
193
final_width = final_width - 15 - 8
195
if SHOW_DESCRIPTIONS:
196
what = test.shortDescription()
198
what = self._ellipsise_unimportant_words(what, final_width, keep_start=True)
201
if what.startswith('bzrlib.tests.'):
203
what = self._ellipsise_unimportant_words(what, final_width)
128
width = osutils.terminal_width()
129
name_width = width - 15
131
if SHOW_DESCRIPTIONS:
132
what = test.shortDescription()
134
if len(what) > name_width:
135
what = what[:name_width-3] + '...'
138
if what.startswith('bzrlib.tests.'):
140
if len(what) > name_width:
141
what = '...' + what[3-name_width:]
142
what = what.ljust(name_width)
143
205
self.stream.write(what)
206
elif self.dots and self.pb is not None:
207
self.pb.update(what, self.testsRun - 1, None)
144
208
self.stream.flush()
209
self._recordTestStartTime()
211
def _recordTestStartTime(self):
212
"""Record that a test has started."""
145
213
self._start_time = time.time()
147
215
def addError(self, test, err):
148
216
if isinstance(err[1], TestSkipped):
149
217
return self.addSkipped(test, err)
150
218
unittest.TestResult.addError(self, test, err)
219
self.extractBenchmarkTime(test)
152
self.stream.writeln("ERROR %s" % self._elapsedTime())
221
self.stream.writeln("ERROR %s" % self._testTimeString())
222
elif self.dots and self.pb is None:
154
223
self.stream.write('E')
225
self.pb.update(self._ellipsise_unimportant_words('ERROR', 13), self.testsRun, None)
226
self.pb.note(self._ellipsise_unimportant_words(
227
test.id() + ': ERROR',
228
osutils.terminal_width()))
155
229
self.stream.flush()
156
230
if self.stop_early:
159
233
def addFailure(self, test, err):
160
234
unittest.TestResult.addFailure(self, test, err)
235
self.extractBenchmarkTime(test)
162
self.stream.writeln(" FAIL %s" % self._elapsedTime())
237
self.stream.writeln(" FAIL %s" % self._testTimeString())
238
elif self.dots and self.pb is None:
164
239
self.stream.write('F')
241
self.pb.update(self._ellipsise_unimportant_words('FAIL', 13), self.testsRun, None)
242
self.pb.note(self._ellipsise_unimportant_words(
243
test.id() + ': FAIL',
244
osutils.terminal_width()))
165
245
self.stream.flush()
166
246
if self.stop_early:
169
249
def addSuccess(self, test):
250
self.extractBenchmarkTime(test)
171
self.stream.writeln(' OK %s' % self._elapsedTime())
252
self.stream.writeln(' OK %s' % self._testTimeString())
253
for bench_called, stats in getattr(test, '_benchcalls', []):
254
self.stream.writeln('LSProf output for %s(%s, %s)' % bench_called)
255
stats.pprint(file=self.stream)
256
elif self.dots and self.pb is None:
173
257
self.stream.write('~')
259
self.pb.update(self._ellipsise_unimportant_words('OK', 13), self.testsRun, None)
174
260
self.stream.flush()
175
261
unittest.TestResult.addSuccess(self, test)
177
263
def addSkipped(self, test, skip_excinfo):
264
self.extractBenchmarkTime(test)
179
print >>self.stream, ' SKIP %s' % self._elapsedTime()
266
print >>self.stream, ' SKIP %s' % self._testTimeString()
180
267
print >>self.stream, ' %s' % skip_excinfo[1]
268
elif self.dots and self.pb is None:
182
269
self.stream.write('S')
271
self.pb.update(self._ellipsise_unimportant_words('SKIP', 13), self.testsRun, None)
183
272
self.stream.flush()
184
273
# seems best to treat this as success from point-of-view of unittest
185
274
# -- it actually does nothing so it barely matters :)
186
unittest.TestResult.addSuccess(self, test)
277
except KeyboardInterrupt:
280
self.addError(test, test.__exc_info())
282
unittest.TestResult.addSuccess(self, test)
188
284
def printErrorList(self, flavour, errors):
189
285
for test, err in errors:
200
296
self.stream.writeln("%s" % err)
203
class TextTestRunner(unittest.TextTestRunner):
299
class TextTestRunner(object):
204
300
stop_on_failure = False
308
self.stream = unittest._WritelnDecorator(stream)
309
self.descriptions = descriptions
310
self.verbosity = verbosity
311
self.keep_output = keep_output
206
314
def _makeResult(self):
207
result = _MyResult(self.stream, self.descriptions, self.verbosity)
315
result = _MyResult(self.stream,
208
319
result.stop_early = self.stop_on_failure
323
"Run the given test case or test suite."
324
result = self._makeResult()
325
startTime = time.time()
326
if self.pb is not None:
327
self.pb.update('Running tests', 0, test.countTestCases())
329
stopTime = time.time()
330
timeTaken = stopTime - startTime
332
self.stream.writeln(result.separator2)
333
run = result.testsRun
334
self.stream.writeln("Ran %d test%s in %.3fs" %
335
(run, run != 1 and "s" or "", timeTaken))
336
self.stream.writeln()
337
if not result.wasSuccessful():
338
self.stream.write("FAILED (")
339
failed, errored = map(len, (result.failures, result.errors))
341
self.stream.write("failures=%d" % failed)
343
if failed: self.stream.write(", ")
344
self.stream.write("errors=%d" % errored)
345
self.stream.writeln(")")
347
self.stream.writeln("OK")
348
if self.pb is not None:
349
self.pb.update('Cleaning up', 0, 1)
350
# This is still a little bogus,
351
# but only a little. Folk not using our testrunner will
352
# have to delete their temp directories themselves.
353
test_root = TestCaseInTempDir.TEST_ROOT
354
if result.wasSuccessful() or not self.keep_output:
355
if test_root is not None:
356
# If LANG=C we probably have created some bogus paths
357
# which rmtree(unicode) will fail to delete
358
# so make sure we are using rmtree(str) to delete everything
359
# except on win32, where rmtree(str) will fail
360
# since it doesn't have the property of byte-stream paths
361
# (they are either ascii or mbcs)
362
if sys.platform == 'win32':
363
# make sure we are using the unicode win32 api
364
test_root = unicode(test_root)
366
test_root = test_root.encode(
367
sys.getfilesystemencoding())
368
osutils.rmtree(test_root)
370
if self.pb is not None:
371
self.pb.note("Failed tests working directories are in '%s'\n",
375
"Failed tests working directories are in '%s'\n" %
377
TestCaseInTempDir.TEST_ROOT = None
378
if self.pb is not None:
212
383
def iter_suite_tests(suite):
213
384
"""Return all tests in a suite, recursing through nested suites"""
230
401
class CommandFailed(Exception):
405
class StringIOWrapper(object):
406
"""A wrapper around cStringIO which just adds an encoding attribute.
408
Internally we can check sys.stdout to see what the output encoding
409
should be. However, cStringIO has no encoding attribute that we can
410
set. So we wrap it instead.
415
def __init__(self, s=None):
417
self.__dict__['_cstring'] = StringIO(s)
419
self.__dict__['_cstring'] = StringIO()
421
def __getattr__(self, name, getattr=getattr):
422
return getattr(self.__dict__['_cstring'], name)
424
def __setattr__(self, name, val):
425
if name == 'encoding':
426
self.__dict__['encoding'] = val
428
return setattr(self._cstring, name, val)
233
431
class TestCase(unittest.TestCase):
234
432
"""Base class for bzr unit tests.
416
628
self._runCleanups()
417
629
unittest.TestCase.tearDown(self)
631
def time(self, callable, *args, **kwargs):
632
"""Run callable and accrue the time it takes to the benchmark time.
634
If lsprofiling is enabled (i.e. by --lsprof-time to bzr selftest) then
635
this will cause lsprofile statistics to be gathered and stored in
638
if self._benchtime is None:
642
if not self._gather_lsprof_in_benchmarks:
643
return callable(*args, **kwargs)
645
# record this benchmark
646
ret, stats = bzrlib.lsprof.profile(callable, *args, **kwargs)
648
self._benchcalls.append(((callable, args, kwargs), stats))
651
self._benchtime += time.time() - start
419
653
def _runCleanups(self):
420
654
"""Run registered cleanup functions.
458
692
errors, and with logging set to something approximating the
459
693
default, so that error reporting can be checked.
461
argv -- arguments to invoke bzr
462
retcode -- expected return code, or None for don't-care.
695
:param argv: arguments to invoke bzr
696
:param retcode: expected return code, or None for don't-care.
697
:param encoding: encoding for sys.stdout and sys.stderr
698
:param stdin: A string to be used as stdin for the command.
466
self.log('run bzr: %s', ' '.join(argv))
701
encoding = bzrlib.user_encoding
702
if stdin is not None:
703
stdin = StringIO(stdin)
704
stdout = StringIOWrapper()
705
stderr = StringIOWrapper()
706
stdout.encoding = encoding
707
stderr.encoding = encoding
709
self.log('run bzr: %r', argv)
467
710
# FIXME: don't call into logging here
468
711
handler = logging.StreamHandler(stderr)
469
handler.setFormatter(bzrlib.trace.QuietFormatter())
470
712
handler.setLevel(logging.INFO)
471
713
logger = logging.getLogger('')
472
714
logger.addHandler(handler)
715
old_ui_factory = bzrlib.ui.ui_factory
716
bzrlib.ui.ui_factory = bzrlib.tests.blackbox.TestUIFactory(
719
bzrlib.ui.ui_factory.stdin = stdin
474
result = self.apply_redirected(None, stdout, stderr,
721
result = self.apply_redirected(stdin, stdout, stderr,
475
722
bzrlib.commands.run_bzr_catch_errors,
478
725
logger.removeHandler(handler)
726
bzrlib.ui.ui_factory = old_ui_factory
479
728
out = stdout.getvalue()
480
729
err = stderr.getvalue()
482
self.log('output:\n%s', out)
731
self.log('output:\n%r', out)
484
self.log('errors:\n%s', err)
733
self.log('errors:\n%r', err)
485
734
if retcode is not None:
486
self.assertEquals(result, retcode)
735
self.assertEquals(retcode, result)
489
738
def run_bzr(self, *args, **kwargs):
496
745
This sends the stdout/stderr results into the test's log,
497
746
where it may be useful for debugging. See also run_captured.
748
:param stdin: A string to be used as stdin for the command.
499
750
retcode = kwargs.pop('retcode', 0)
500
return self.run_bzr_captured(args, retcode)
751
encoding = kwargs.pop('encoding', None)
752
stdin = kwargs.pop('stdin', None)
753
return self.run_bzr_captured(args, retcode=retcode, encoding=encoding, stdin=stdin)
755
def run_bzr_decode(self, *args, **kwargs):
756
if kwargs.has_key('encoding'):
757
encoding = kwargs['encoding']
759
encoding = bzrlib.user_encoding
760
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
762
def run_bzr_error(self, error_regexes, *args, **kwargs):
763
"""Run bzr, and check that stderr contains the supplied regexes
765
:param error_regexes: Sequence of regular expressions which
766
must each be found in the error output. The relative ordering
768
:param args: command-line arguments for bzr
769
:param kwargs: Keyword arguments which are interpreted by run_bzr
770
This function changes the default value of retcode to be 3,
771
since in most cases this is run when you expect bzr to fail.
772
:return: (out, err) The actual output of running the command (in case you
773
want to do more inspection)
776
# Make sure that commit is failing because there is nothing to do
777
self.run_bzr_error(['no changes to commit'],
778
'commit', '-m', 'my commit comment')
779
# Make sure --strict is handling an unknown file, rather than
780
# giving us the 'nothing to do' error
781
self.build_tree(['unknown'])
782
self.run_bzr_error(['Commit refused because there are unknown files'],
783
'commit', '--strict', '-m', 'my commit comment')
785
kwargs.setdefault('retcode', 3)
786
out, err = self.run_bzr(*args, **kwargs)
787
for regex in error_regexes:
788
self.assertContainsRe(err, regex)
791
def run_bzr_subprocess(self, *args, **kwargs):
792
"""Run bzr in a subprocess for testing.
794
This starts a new Python interpreter and runs bzr in there.
795
This should only be used for tests that have a justifiable need for
796
this isolation: e.g. they are testing startup time, or signal
797
handling, or early startup code, etc. Subprocess code can't be
798
profiled or debugged so easily.
800
:param retcode: The status code that is expected. Defaults to 0. If
801
None is supplied, the status code is not checked.
803
bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
805
process = Popen([sys.executable, bzr_path]+args, stdout=PIPE,
807
out = process.stdout.read()
808
err = process.stderr.read()
809
retcode = process.wait()
810
supplied_retcode = kwargs.get('retcode', 0)
811
if supplied_retcode is not None:
812
assert supplied_retcode == retcode
502
815
def check_inventory_shape(self, inv, shape):
503
816
"""Compare an inventory to a list of expected names.
678
993
raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
679
content = "contents of %s%s" % (name, end)
680
transport.put(urlescape(name), StringIO(content))
994
content = "contents of %s%s" % (name.encode('utf-8'), end)
995
# Technically 'put()' is the right command. However, put
996
# uses an AtomicFile, which requires an extra rename into place
997
# As long as the files didn't exist in the past, append() will
998
# do the same thing as put()
999
# On jam's machine, make_kernel_like_tree is:
1000
# put: 4.5-7.5s (averaging 6s)
1002
transport.append(urlutils.escape(name), StringIO(content))
682
1004
def build_tree_contents(self, shape):
683
1005
build_tree_contents(shape)
793
1116
self.assertTrue(t.is_readonly())
796
def make_branch(self, relpath):
1119
def make_branch(self, relpath, format=None):
797
1120
"""Create a branch on the transport at relpath."""
798
repo = self.make_repository(relpath)
1121
repo = self.make_repository(relpath, format=format)
799
1122
return repo.bzrdir.create_branch()
801
def make_bzrdir(self, relpath):
1124
def make_bzrdir(self, relpath, format=None):
803
1126
url = self.get_url(relpath)
804
segments = relpath.split('/')
1127
mutter('relpath %r => url %r', relpath, url)
1128
segments = url.split('/')
805
1129
if segments and segments[-1] not in ('', '.'):
806
parent = self.get_url('/'.join(segments[:-1]))
1130
parent = '/'.join(segments[:-1])
807
1131
t = get_transport(parent)
809
1133
t.mkdir(segments[-1])
810
1134
except errors.FileExists:
812
return bzrlib.bzrdir.BzrDir.create(url)
1137
format=bzrlib.bzrdir.BzrDirFormat.get_default_format()
1138
# FIXME: make this use a single transport someday. RBC 20060418
1139
return format.initialize_on_transport(get_transport(relpath))
813
1140
except errors.UninitializableFormat:
814
raise TestSkipped("Format %s is not initializable.")
1141
raise TestSkipped("Format %s is not initializable." % format)
816
def make_repository(self, relpath, shared=False):
1143
def make_repository(self, relpath, shared=False, format=None):
817
1144
"""Create a repository on our default transport at relpath."""
818
made_control = self.make_bzrdir(relpath)
1145
made_control = self.make_bzrdir(relpath, format=format)
819
1146
return made_control.create_repository(shared=shared)
821
def make_branch_and_tree(self, relpath):
1148
def make_branch_and_tree(self, relpath, format=None):
822
1149
"""Create a branch on the transport and a tree locally.
824
1151
Returns the tree.
883
1210
def run_suite(suite, name='test', verbose=False, pattern=".*",
884
1211
stop_on_failure=False, keep_output=False,
1212
transport=None, lsprof_timed=None):
886
1213
TestCaseInTempDir._TEST_NAME = name
1214
TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1220
pb = progress.ProgressBar()
891
1221
runner = TextTestRunner(stream=sys.stdout,
1223
verbosity=verbosity,
1224
keep_output=keep_output,
894
1226
runner.stop_on_failure=stop_on_failure
895
1227
if pattern != '.*':
896
1228
suite = filter_suite_by_re(suite, pattern)
897
1229
result = runner.run(suite)
898
# This is still a little bogus,
899
# but only a little. Folk not using our testrunner will
900
# have to delete their temp directories themselves.
901
test_root = TestCaseInTempDir.TEST_ROOT
902
if result.wasSuccessful() or not keep_output:
903
if test_root is not None:
904
print 'Deleting test root %s...' % test_root
906
shutil.rmtree(test_root)
910
print "Failed tests working directories are in '%s'\n" % TestCaseInTempDir.TEST_ROOT
911
1230
return result.wasSuccessful()
914
1233
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
915
1234
keep_output=False,
1236
test_suite_factory=None,
917
1238
"""Run the whole test suite under the enhanced runner"""
1239
# XXX: Very ugly way to do this...
1240
# Disable warning about old formats because we don't want it to disturb
1241
# any blackbox tests.
1242
from bzrlib import repository
1243
repository._deprecation_warning_done = True
918
1245
global default_transport
919
1246
if transport is None:
920
1247
transport = default_transport
921
1248
old_transport = default_transport
922
1249
default_transport = transport
1251
if test_suite_factory is None:
1252
suite = test_suite()
1254
suite = test_suite_factory()
925
1255
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
926
1256
stop_on_failure=stop_on_failure, keep_output=keep_output,
1257
transport=transport,
1258
lsprof_timed=lsprof_timed)
929
1260
default_transport = old_transport
933
1263
def test_suite():
934
"""Build and return TestSuite for the whole program."""
935
from doctest import DocTestSuite
937
global MODULES_TO_DOCTEST
1264
"""Build and return TestSuite for the whole of bzrlib.
1266
This function can be replaced if you need to change the default test
1267
suite on a global basis, but it is not encouraged.
940
1270
'bzrlib.tests.test_ancestry',
941
'bzrlib.tests.test_annotate',
942
1271
'bzrlib.tests.test_api',
1272
'bzrlib.tests.test_atomicfile',
943
1273
'bzrlib.tests.test_bad_files',
944
'bzrlib.tests.test_basis_inventory',
945
1274
'bzrlib.tests.test_branch',
1275
'bzrlib.tests.test_bundle',
946
1276
'bzrlib.tests.test_bzrdir',
947
1277
'bzrlib.tests.test_command',
948
1278
'bzrlib.tests.test_commit',
988
1322
'bzrlib.tests.test_sftp_transport',
989
1323
'bzrlib.tests.test_smart_add',
990
1324
'bzrlib.tests.test_source',
1325
'bzrlib.tests.test_status',
991
1326
'bzrlib.tests.test_store',
992
1327
'bzrlib.tests.test_symbol_versioning',
993
1328
'bzrlib.tests.test_testament',
1329
'bzrlib.tests.test_textfile',
1330
'bzrlib.tests.test_textmerge',
994
1331
'bzrlib.tests.test_trace',
995
1332
'bzrlib.tests.test_transactions',
996
1333
'bzrlib.tests.test_transform',
997
1334
'bzrlib.tests.test_transport',
1335
'bzrlib.tests.test_tree',
998
1336
'bzrlib.tests.test_tsort',
1337
'bzrlib.tests.test_tuned_gzip',
999
1338
'bzrlib.tests.test_ui',
1000
1339
'bzrlib.tests.test_upgrade',
1340
'bzrlib.tests.test_urlutils',
1001
1341
'bzrlib.tests.test_versionedfile',
1002
1342
'bzrlib.tests.test_weave',
1003
1343
'bzrlib.tests.test_whitebox',
1005
1345
'bzrlib.tests.test_xml',
1007
1347
test_transport_implementations = [
1008
'bzrlib.tests.test_transport_implementations']
1010
TestCase.BZRPATH = osutils.pathjoin(
1011
osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr')
1012
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
1013
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
1016
# python2.4's TestLoader.loadTestsFromNames gives very poor
1017
# errors if it fails to load a named module - no indication of what's
1018
# actually wrong, just "no such module". We should probably override that
1019
# class, but for the moment just load them ourselves. (mbp 20051202)
1020
loader = TestLoader()
1348
'bzrlib.tests.test_transport_implementations',
1349
'bzrlib.tests.test_read_bundle',
1351
suite = TestUtil.TestSuite()
1352
loader = TestUtil.TestLoader()
1353
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1021
1354
from bzrlib.transport import TransportTestProviderAdapter
1022
1355
adapter = TransportTestProviderAdapter()
1023
1356
adapt_modules(test_transport_implementations, adapter, loader, suite)
1024
for mod_name in testmod_names:
1025
mod = _load_module_by_name(mod_name)
1026
suite.addTest(loader.loadTestsFromModule(mod))
1027
1357
for package in packages_to_test():
1028
1358
suite.addTest(package.test_suite())
1029
1359
for m in MODULES_TO_TEST:
1030
1360
suite.addTest(loader.loadTestsFromModule(m))
1031
for m in (MODULES_TO_DOCTEST):
1032
suite.addTest(DocTestSuite(m))
1361
for m in MODULES_TO_DOCTEST:
1362
suite.addTest(doctest.DocTestSuite(m))
1033
1363
for name, plugin in bzrlib.plugin.all_plugins().items():
1034
1364
if getattr(plugin, 'test_suite', None) is not None:
1035
1365
suite.addTest(plugin.test_suite())
1039
1369
def adapt_modules(mods_list, adapter, loader, suite):
1040
1370
"""Adapt the modules in mods_list using adapter and add to suite."""
1041
for mod_name in mods_list:
1042
mod = _load_module_by_name(mod_name)
1043
for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
1044
suite.addTests(adapter.adapt(test))
1047
def _load_module_by_name(mod_name):
1048
parts = mod_name.split('.')
1049
module = __import__(mod_name)
1051
# for historical reasons python returns the top-level module even though
1052
# it loads the submodule; we need to walk down to get the one we want.
1054
module = getattr(module, parts.pop(0))
1371
for test in iter_suite_tests(loader.loadTestsFromModuleNames(mods_list)):
1372
suite.addTests(adapter.adapt(test))