15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from testsweet import TestBase, run_suite, InTempDir
18
# TODO: Perhaps there should be an API to find out if bzr running under the
19
# test suite -- some plugins might want to avoid making intrusive changes if
20
# this is the case. However, we want behaviour under to test to diverge as
21
# little as possible, so this should be used rarely if it's added at all.
22
# (Suggestion from j-a-meinel, 2005-11-24)
24
from cStringIO import StringIO
39
import bzrlib.commands
40
from bzrlib.errors import (BzrError,
42
UninitializableFormat,
44
import bzrlib.inventory
45
import bzrlib.iterablefile
48
import bzrlib.osutils as osutils
52
from bzrlib.transport import urlescape
53
import bzrlib.transport
54
from bzrlib.transport.local import LocalRelpathServer
55
from bzrlib.transport.readonly import ReadonlyServer
56
from bzrlib.trace import mutter
57
from bzrlib.tests.TestUtil import TestLoader, TestSuite
58
from bzrlib.tests.treeshape import build_tree_contents
59
from bzrlib.workingtree import WorkingTree
61
default_transport = LocalRelpathServer
20
63
MODULES_TO_TEST = []
21
MODULES_TO_DOCTEST = []
24
from unittest import TestLoader, TestSuite
25
import bzrlib, bzrlib.store, bzrlib.inventory, bzrlib.branch
26
import bzrlib.osutils, bzrlib.commands, bzrlib.merge3, bzrlib.plugin
27
global MODULES_TO_TEST, MODULES_TO_DOCTEST
29
import bzrlib.selftest.whitebox
30
import bzrlib.selftest.blackbox
31
import bzrlib.selftest.versioning
32
import bzrlib.selftest.testmerge3
33
import bzrlib.selftest.testhashcache
34
import bzrlib.selftest.testrevisionnamespaces
35
import bzrlib.selftest.testbranch
36
import bzrlib.selftest.teststatus
37
import bzrlib.selftest.testinv
38
import bzrlib.merge_core
64
MODULES_TO_DOCTEST = [
75
def packages_to_test():
76
"""Return a list of packages to test.
78
The packages are not globally imported so that import failures are
79
triggered when running selftest, not when importing the command.
82
import bzrlib.tests.blackbox
83
import bzrlib.tests.branch_implementations
86
bzrlib.tests.branch_implementations,
90
class _MyResult(unittest._TextTestResult):
93
Shows output in a different format, including displaying runtime for tests.
97
def _elapsedTime(self):
98
return "%5dms" % (1000 * (time.time() - self._start_time))
100
def startTest(self, test):
101
unittest.TestResult.startTest(self, test)
102
# In a short description, the important words are in
103
# the beginning, but in an id, the important words are
105
SHOW_DESCRIPTIONS = False
107
width = osutils.terminal_width()
108
name_width = width - 15
110
if SHOW_DESCRIPTIONS:
111
what = test.shortDescription()
113
if len(what) > name_width:
114
what = what[:name_width-3] + '...'
117
if what.startswith('bzrlib.tests.'):
119
if len(what) > name_width:
120
what = '...' + what[3-name_width:]
121
what = what.ljust(name_width)
122
self.stream.write(what)
124
self._start_time = time.time()
126
def addError(self, test, err):
127
if isinstance(err[1], TestSkipped):
128
return self.addSkipped(test, err)
129
unittest.TestResult.addError(self, test, err)
131
self.stream.writeln("ERROR %s" % self._elapsedTime())
133
self.stream.write('E')
138
def addFailure(self, test, err):
139
unittest.TestResult.addFailure(self, test, err)
141
self.stream.writeln(" FAIL %s" % self._elapsedTime())
143
self.stream.write('F')
148
def addSuccess(self, test):
150
self.stream.writeln(' OK %s' % self._elapsedTime())
152
self.stream.write('~')
154
unittest.TestResult.addSuccess(self, test)
156
def addSkipped(self, test, skip_excinfo):
158
print >>self.stream, ' SKIP %s' % self._elapsedTime()
159
print >>self.stream, ' %s' % skip_excinfo[1]
161
self.stream.write('S')
163
# seems best to treat this as success from point-of-view of unittest
164
# -- it actually does nothing so it barely matters :)
165
unittest.TestResult.addSuccess(self, test)
167
def printErrorList(self, flavour, errors):
168
for test, err in errors:
169
self.stream.writeln(self.separator1)
170
self.stream.writeln("%s: %s" % (flavour, self.getDescription(test)))
171
if getattr(test, '_get_log', None) is not None:
173
print >>self.stream, \
174
('vvvv[log from %s]' % test.id()).ljust(78,'-')
175
print >>self.stream, test._get_log()
176
print >>self.stream, \
177
('^^^^[log from %s]' % test.id()).ljust(78,'-')
178
self.stream.writeln(self.separator2)
179
self.stream.writeln("%s" % err)
182
class TextTestRunner(unittest.TextTestRunner):
183
stop_on_failure = False
185
def _makeResult(self):
186
result = _MyResult(self.stream, self.descriptions, self.verbosity)
187
result.stop_early = self.stop_on_failure
191
def iter_suite_tests(suite):
192
"""Return all tests in a suite, recursing through nested suites"""
193
for item in suite._tests:
194
if isinstance(item, unittest.TestCase):
196
elif isinstance(item, unittest.TestSuite):
197
for r in iter_suite_tests(item):
200
raise Exception('unknown object %r inside test suite %r'
204
class TestSkipped(Exception):
205
"""Indicates that a test was intentionally skipped, rather than failing."""
209
class CommandFailed(Exception):
212
class TestCase(unittest.TestCase):
213
"""Base class for bzr unit tests.
215
Tests that need access to disk resources should subclass
216
TestCaseInTempDir not TestCase.
218
Error and debug log messages are redirected from their usual
219
location into a temporary file, the contents of which can be
220
retrieved by _get_log(). We use a real OS file, not an in-memory object,
221
so that it can also capture file IO. When the test completes this file
222
is read into memory and removed from disk.
224
There are also convenience functions to invoke bzr's command-line
225
routine, and to build and check bzr trees.
227
In addition to the usual method of overriding tearDown(), this class also
228
allows subclasses to register functions into the _cleanups list, which is
229
run in order as the object is torn down. It's less likely this will be
230
accidentally overlooked.
234
_log_file_name = None
237
def __init__(self, methodName='testMethod'):
238
super(TestCase, self).__init__(methodName)
242
unittest.TestCase.setUp(self)
243
self._cleanEnvironment()
244
bzrlib.trace.disable_default_logging()
247
def _ndiff_strings(self, a, b):
248
"""Return ndiff between two strings containing lines.
250
A trailing newline is added if missing to make the strings
252
if b and b[-1] != '\n':
254
if a and a[-1] != '\n':
256
difflines = difflib.ndiff(a.splitlines(True),
258
linejunk=lambda x: False,
259
charjunk=lambda x: False)
260
return ''.join(difflines)
262
def assertEqualDiff(self, a, b):
263
"""Assert two texts are equal, if not raise an exception.
265
This is intended for use with multi-line strings where it can
266
be hard to find the differences by eye.
268
# TODO: perhaps override assertEquals to call this for strings?
271
raise AssertionError("texts not equal:\n" +
272
self._ndiff_strings(a, b))
274
def assertStartsWith(self, s, prefix):
275
if not s.startswith(prefix):
276
raise AssertionError('string %r does not start with %r' % (s, prefix))
278
def assertEndsWith(self, s, suffix):
279
if not s.endswith(prefix):
280
raise AssertionError('string %r does not end with %r' % (s, suffix))
282
def assertContainsRe(self, haystack, needle_re):
283
"""Assert that a contains something matching a regular expression."""
284
if not re.search(needle_re, haystack):
285
raise AssertionError('pattern "%s" not found in "%s"'
286
% (needle_re, haystack))
288
def AssertSubset(self, sublist, superlist):
289
"""Assert that every entry in sublist is present in superlist."""
291
for entry in sublist:
292
if entry not in superlist:
293
missing.append(entry)
295
raise AssertionError("value(s) %r not present in container %r" %
296
(missing, superlist))
298
def assertIs(self, left, right):
299
if not (left is right):
300
raise AssertionError("%r is not %r." % (left, right))
302
def assertTransportMode(self, transport, path, mode):
303
"""Fail if a path does not have mode mode.
305
If modes are not supported on this platform, the test is skipped.
307
if sys.platform == 'win32':
309
path_stat = transport.stat(path)
310
actual_mode = stat.S_IMODE(path_stat.st_mode)
311
self.assertEqual(mode, actual_mode,
312
'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
314
def _startLogFile(self):
315
"""Send bzr and test log messages to a temporary file.
317
The file is removed as the test is torn down.
319
fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
320
encoder, decoder, stream_reader, stream_writer = codecs.lookup('UTF-8')
321
self._log_file = stream_writer(os.fdopen(fileno, 'w+'))
322
self._log_nonce = bzrlib.trace.enable_test_log(self._log_file)
323
self._log_file_name = name
324
self.addCleanup(self._finishLogFile)
326
def _finishLogFile(self):
327
"""Finished with the log file.
329
Read contents into memory, close, and delete.
331
bzrlib.trace.disable_test_log(self._log_nonce)
332
self._log_file.seek(0)
333
self._log_contents = self._log_file.read()
334
self._log_file.close()
335
os.remove(self._log_file_name)
336
self._log_file = self._log_file_name = None
338
def addCleanup(self, callable):
339
"""Arrange to run a callable when this case is torn down.
341
Callables are run in the reverse of the order they are registered,
342
ie last-in first-out.
344
if callable in self._cleanups:
345
raise ValueError("cleanup function %r already registered on %s"
347
self._cleanups.append(callable)
349
def _cleanEnvironment(self):
352
'APPDATA': os.getcwd(),
357
self.addCleanup(self._restoreEnvironment)
358
for name, value in new_env.iteritems():
359
self._captureVar(name, value)
362
def _captureVar(self, name, newvalue):
363
"""Set an environment variable, preparing it to be reset when finished."""
364
self.__old_env[name] = os.environ.get(name, None)
366
if name in os.environ:
369
os.environ[name] = newvalue
372
def _restoreVar(name, value):
374
if name in os.environ:
377
os.environ[name] = value
379
def _restoreEnvironment(self):
380
for name, value in self.__old_env.iteritems():
381
self._restoreVar(name, value)
385
unittest.TestCase.tearDown(self)
387
def _runCleanups(self):
388
"""Run registered cleanup functions.
390
This should only be called from TestCase.tearDown.
392
# TODO: Perhaps this should keep running cleanups even if
394
for cleanup_fn in reversed(self._cleanups):
397
def log(self, *args):
401
"""Return as a string the log for this test"""
402
if self._log_file_name:
403
return open(self._log_file_name).read()
405
return self._log_contents
406
# TODO: Delete the log after it's been read in
408
def capture(self, cmd, retcode=0):
409
"""Shortcut that splits cmd into words, runs, and returns stdout"""
410
return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
412
def run_bzr_captured(self, argv, retcode=0):
413
"""Invoke bzr and return (stdout, stderr).
415
Useful for code that wants to check the contents of the
416
output, the way error messages are presented, etc.
418
This should be the main method for tests that want to exercise the
419
overall behavior of the bzr application (rather than a unit test
420
or a functional test of the library.)
422
Much of the old code runs bzr by forking a new copy of Python, but
423
that is slower, harder to debug, and generally not necessary.
425
This runs bzr through the interface that catches and reports
426
errors, and with logging set to something approximating the
427
default, so that error reporting can be checked.
429
argv -- arguments to invoke bzr
430
retcode -- expected return code, or None for don't-care.
434
self.log('run bzr: %s', ' '.join(argv))
435
# FIXME: don't call into logging here
436
handler = logging.StreamHandler(stderr)
437
handler.setFormatter(bzrlib.trace.QuietFormatter())
438
handler.setLevel(logging.INFO)
439
logger = logging.getLogger('')
440
logger.addHandler(handler)
442
result = self.apply_redirected(None, stdout, stderr,
443
bzrlib.commands.run_bzr_catch_errors,
446
logger.removeHandler(handler)
447
out = stdout.getvalue()
448
err = stderr.getvalue()
450
self.log('output:\n%s', out)
452
self.log('errors:\n%s', err)
453
if retcode is not None:
454
self.assertEquals(result, retcode)
457
def run_bzr(self, *args, **kwargs):
458
"""Invoke bzr, as if it were run from the command line.
460
This should be the main method for tests that want to exercise the
461
overall behavior of the bzr application (rather than a unit test
462
or a functional test of the library.)
464
This sends the stdout/stderr results into the test's log,
465
where it may be useful for debugging. See also run_captured.
467
retcode = kwargs.pop('retcode', 0)
468
return self.run_bzr_captured(args, retcode)
470
def check_inventory_shape(self, inv, shape):
471
"""Compare an inventory to a list of expected names.
473
Fail if they are not precisely equal.
476
shape = list(shape) # copy
477
for path, ie in inv.entries():
478
name = path.replace('\\', '/')
486
self.fail("expected paths not found in inventory: %r" % shape)
488
self.fail("unexpected paths found in inventory: %r" % extras)
490
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
491
a_callable=None, *args, **kwargs):
492
"""Call callable with redirected std io pipes.
494
Returns the return code."""
495
if not callable(a_callable):
496
raise ValueError("a_callable must be callable.")
500
if getattr(self, "_log_file", None) is not None:
501
stdout = self._log_file
505
if getattr(self, "_log_file", None is not None):
506
stderr = self._log_file
509
real_stdin = sys.stdin
510
real_stdout = sys.stdout
511
real_stderr = sys.stderr
516
return a_callable(*args, **kwargs)
518
sys.stdout = real_stdout
519
sys.stderr = real_stderr
520
sys.stdin = real_stdin
523
BzrTestBase = TestCase
526
class TestCaseInTempDir(TestCase):
527
"""Derived class that runs a test within a temporary directory.
529
This is useful for tests that need to create a branch, etc.
531
The directory is created in a slightly complex way: for each
532
Python invocation, a new temporary top-level directory is created.
533
All test cases create their own directory within that. If the
534
tests complete successfully, the directory is removed.
536
InTempDir is an old alias for FunctionalTestCase.
541
OVERRIDE_PYTHON = 'python'
543
def check_file_contents(self, filename, expect):
544
self.log("check contents of file %s" % filename)
545
contents = file(filename, 'r').read()
546
if contents != expect:
547
self.log("expected: %r" % expect)
548
self.log("actually: %r" % contents)
549
self.fail("contents of %s not as expected" % filename)
551
def _make_test_root(self):
552
if TestCaseInTempDir.TEST_ROOT is not None:
556
root = u'test%04d.tmp' % i
560
if e.errno == errno.EEXIST:
565
# successfully created
566
TestCaseInTempDir.TEST_ROOT = osutils.abspath(root)
568
# make a fake bzr directory there to prevent any tests propagating
569
# up onto the source directory's real branch
570
os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr'))
573
super(TestCaseInTempDir, self).setUp()
574
self._make_test_root()
575
_currentdir = os.getcwdu()
576
short_id = self.id().replace('bzrlib.tests.', '') \
577
.replace('__main__.', '')
578
self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id)
579
os.mkdir(self.test_dir)
580
os.chdir(self.test_dir)
581
os.environ['HOME'] = self.test_dir
582
os.environ['APPDATA'] = self.test_dir
583
def _leaveDirectory():
584
os.chdir(_currentdir)
585
self.addCleanup(_leaveDirectory)
587
def build_tree(self, shape, line_endings='native', transport=None):
588
"""Build a test tree according to a pattern.
590
shape is a sequence of file specifications. If the final
591
character is '/', a directory is created.
593
This doesn't add anything to a branch.
594
:param line_endings: Either 'binary' or 'native'
595
in binary mode, exact contents are written
596
in native mode, the line endings match the
597
default platform endings.
599
:param transport: A transport to write to, for building trees on
600
VFS's. If the transport is readonly or None,
601
"." is opened automatically.
603
# XXX: It's OK to just create them using forward slashes on windows?
604
if transport is None or transport.is_readonly():
605
transport = bzrlib.transport.get_transport(".")
607
self.assert_(isinstance(name, basestring))
609
transport.mkdir(urlescape(name[:-1]))
611
if line_endings == 'binary':
613
elif line_endings == 'native':
616
raise BzrError('Invalid line ending request %r' % (line_endings,))
617
content = "contents of %s%s" % (name, end)
618
transport.put(urlescape(name), StringIO(content))
620
def build_tree_contents(self, shape):
621
build_tree_contents(shape)
623
def failUnlessExists(self, path):
624
"""Fail unless path, which may be abs or relative, exists."""
625
self.failUnless(osutils.lexists(path))
627
def failIfExists(self, path):
628
"""Fail if path, which may be abs or relative, exists."""
629
self.failIf(osutils.lexists(path))
631
def assertFileEqual(self, content, path):
632
"""Fail if path does not contain 'content'."""
633
self.failUnless(osutils.lexists(path))
634
self.assertEqualDiff(content, open(path, 'r').read())
637
class TestCaseWithTransport(TestCaseInTempDir):
638
"""A test case that provides get_url and get_readonly_url facilities.
640
These back onto two transport servers, one for readonly access and one for
643
If no explicit class is provided for readonly access, a
644
ReadonlyTransportDecorator is used instead which allows the use of non disk
645
based read write transports.
647
If an explicit class is provided for readonly access, that server and the
648
readwrite one must both define get_url() as resolving to os.getcwd().
651
def __init__(self, methodName='testMethod'):
652
super(TestCaseWithTransport, self).__init__(methodName)
653
self.__readonly_server = None
655
self.transport_server = default_transport
656
self.transport_readonly_server = None
658
def get_readonly_url(self, relpath=None):
659
"""Get a URL for the readonly transport.
661
This will either be backed by '.' or a decorator to the transport
662
used by self.get_url()
663
relpath provides for clients to get a path relative to the base url.
664
These should only be downwards relative, not upwards.
666
if self.__readonly_server is None:
667
if self.transport_readonly_server is None:
668
# readonly decorator requested
669
# bring up the server
671
self.__readonly_server = ReadonlyServer()
672
self.__readonly_server.setUp(self.__server)
674
self.__readonly_server = self.transport_readonly_server()
675
self.__readonly_server.setUp()
676
self.addCleanup(self.__readonly_server.tearDown)
677
base = self.__readonly_server.get_url()
678
if relpath is not None:
679
if not base.endswith('/'):
681
base = base + relpath
684
def get_url(self, relpath=None):
685
"""Get a URL for the readwrite transport.
687
This will either be backed by '.' or to an equivalent non-file based
689
relpath provides for clients to get a path relative to the base url.
690
These should only be downwards relative, not upwards.
692
if self.__server is None:
693
self.__server = self.transport_server()
694
self.__server.setUp()
695
self.addCleanup(self.__server.tearDown)
696
base = self.__server.get_url()
697
if relpath is not None and relpath != '.':
698
if not base.endswith('/'):
700
base = base + relpath
703
def make_branch(self, relpath):
704
"""Create a branch on the transport at relpath."""
706
url = self.get_url(relpath)
707
segments = relpath.split('/')
708
if segments and segments[-1] not in ('', '.'):
709
parent = self.get_url('/'.join(segments[:-1]))
710
t = bzrlib.transport.get_transport(parent)
712
t.mkdir(segments[-1])
715
return bzrlib.branch.Branch.create(url)
716
except UninitializableFormat:
717
raise TestSkipped("Format %s is not initializable.")
719
def make_branch_and_tree(self, relpath):
720
"""Create a branch on the transport and a tree locally.
724
b = self.make_branch(relpath)
725
return WorkingTree.create(b, relpath)
728
class ChrootedTestCase(TestCaseWithTransport):
729
"""A support class that provides readonly urls outside the local namespace.
731
This is done by checking if self.transport_server is a MemoryServer. if it
732
is then we are chrooted already, if it is not then an HttpServer is used
735
TODO RBC 20060127: make this an option to TestCaseWithTransport so it can
736
be used without needed to redo it when a different
741
super(ChrootedTestCase, self).setUp()
742
if not self.transport_server == bzrlib.transport.memory.MemoryServer:
743
self.transport_readonly_server = bzrlib.transport.http.HttpServer
746
def filter_suite_by_re(suite, pattern):
748
filter_re = re.compile(pattern)
749
for test in iter_suite_tests(suite):
750
if filter_re.search(test.id()):
755
def run_suite(suite, name='test', verbose=False, pattern=".*",
756
stop_on_failure=False, keep_output=False,
758
TestCaseInTempDir._TEST_NAME = name
763
runner = TextTestRunner(stream=sys.stdout,
766
runner.stop_on_failure=stop_on_failure
768
suite = filter_suite_by_re(suite, pattern)
769
result = runner.run(suite)
770
# This is still a little bogus,
771
# but only a little. Folk not using our testrunner will
772
# have to delete their temp directories themselves.
773
if result.wasSuccessful() or not keep_output:
774
if TestCaseInTempDir.TEST_ROOT is not None:
775
shutil.rmtree(TestCaseInTempDir.TEST_ROOT)
777
print "Failed tests working directories are in '%s'\n" % TestCaseInTempDir.TEST_ROOT
778
return result.wasSuccessful()
781
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
784
"""Run the whole test suite under the enhanced runner"""
785
global default_transport
786
if transport is None:
787
transport = default_transport
788
old_transport = default_transport
789
default_transport = transport
792
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
793
stop_on_failure=stop_on_failure, keep_output=keep_output,
796
default_transport = old_transport
801
"""Build and return TestSuite for the whole program."""
39
802
from doctest import DocTestSuite
46
for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,
47
bzrlib.osutils, bzrlib.commands, bzrlib.merge3):
48
if m not in MODULES_TO_DOCTEST:
49
MODULES_TO_DOCTEST.append(m)
51
for m in (bzrlib.selftest.whitebox,
52
bzrlib.selftest.versioning,
53
bzrlib.selftest.testinv,
54
bzrlib.selftest.testmerge3,
55
bzrlib.selftest.testhashcache,
56
bzrlib.selftest.teststatus,
57
bzrlib.selftest.blackbox,
58
bzrlib.selftest.testhashcache,
59
bzrlib.selftest.testrevisionnamespaces,
60
bzrlib.selftest.testbranch,
62
if m not in MODULES_TO_TEST:
63
MODULES_TO_TEST.append(m)
66
TestBase.BZRPATH = os.path.join(os.path.realpath(os.path.dirname(bzrlib.__path__[0])), 'bzr')
67
print '%-30s %s' % ('bzr binary', TestBase.BZRPATH)
804
global MODULES_TO_DOCTEST
807
'bzrlib.tests.test_ancestry',
808
'bzrlib.tests.test_annotate',
809
'bzrlib.tests.test_api',
810
'bzrlib.tests.test_bad_files',
811
'bzrlib.tests.test_basis_inventory',
812
'bzrlib.tests.test_branch',
813
'bzrlib.tests.test_command',
814
'bzrlib.tests.test_commit',
815
'bzrlib.tests.test_commit_merge',
816
'bzrlib.tests.test_config',
817
'bzrlib.tests.test_conflicts',
818
'bzrlib.tests.test_diff',
819
'bzrlib.tests.test_decorators',
820
'bzrlib.tests.test_fetch',
821
'bzrlib.tests.test_fileid_involved',
822
'bzrlib.tests.test_gpg',
823
'bzrlib.tests.test_graph',
824
'bzrlib.tests.test_hashcache',
825
'bzrlib.tests.test_http',
826
'bzrlib.tests.test_identitymap',
827
'bzrlib.tests.test_inv',
828
'bzrlib.tests.test_lockable_files',
829
'bzrlib.tests.test_log',
830
'bzrlib.tests.test_merge',
831
'bzrlib.tests.test_merge3',
832
'bzrlib.tests.test_merge_core',
833
'bzrlib.tests.test_missing',
834
'bzrlib.tests.test_msgeditor',
835
'bzrlib.tests.test_nonascii',
836
'bzrlib.tests.test_options',
837
'bzrlib.tests.test_osutils',
838
'bzrlib.tests.test_parent',
839
'bzrlib.tests.test_permissions',
840
'bzrlib.tests.test_plugins',
841
'bzrlib.tests.test_revision',
842
'bzrlib.tests.test_revisionnamespaces',
843
'bzrlib.tests.test_revprops',
844
'bzrlib.tests.test_reweave',
845
'bzrlib.tests.test_rio',
846
'bzrlib.tests.test_sampler',
847
'bzrlib.tests.test_selftest',
848
'bzrlib.tests.test_setup',
849
'bzrlib.tests.test_sftp_transport',
850
'bzrlib.tests.test_smart_add',
851
'bzrlib.tests.test_source',
852
'bzrlib.tests.test_store',
853
'bzrlib.tests.test_symbol_versioning',
854
'bzrlib.tests.test_testament',
855
'bzrlib.tests.test_trace',
856
'bzrlib.tests.test_transactions',
857
'bzrlib.tests.test_transport',
858
'bzrlib.tests.test_tsort',
859
'bzrlib.tests.test_ui',
860
'bzrlib.tests.test_uncommit',
861
'bzrlib.tests.test_upgrade',
862
'bzrlib.tests.test_weave',
863
'bzrlib.tests.test_whitebox',
864
'bzrlib.tests.test_workingtree',
865
'bzrlib.tests.test_xml',
867
test_transport_implementations = [
868
'bzrlib.tests.test_transport_implementations']
870
TestCase.BZRPATH = osutils.pathjoin(
871
osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr')
872
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
873
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
71
875
suite = TestSuite()
73
# should also test bzrlib.merge_core, but they seem to be out of date with
77
# XXX: python2.3's TestLoader() doesn't seem to find all the
78
# tests; don't know why
876
# python2.4's TestLoader.loadTestsFromNames gives very poor
877
# errors if it fails to load a named module - no indication of what's
878
# actually wrong, just "no such module". We should probably override that
879
# class, but for the moment just load them ourselves. (mbp 20051202)
880
loader = TestLoader()
881
from bzrlib.transport import TransportTestProviderAdapter
882
adapter = TransportTestProviderAdapter()
883
adapt_modules(test_transport_implementations, adapter, loader, suite)
884
for mod_name in testmod_names:
885
mod = _load_module_by_name(mod_name)
886
suite.addTest(loader.loadTestsFromModule(mod))
887
for package in packages_to_test():
888
suite.addTest(package.test_suite())
79
889
for m in MODULES_TO_TEST:
80
suite.addTest(TestLoader().loadTestsFromModule(m))
890
suite.addTest(loader.loadTestsFromModule(m))
82
891
for m in (MODULES_TO_DOCTEST):
83
892
suite.addTest(DocTestSuite(m))
85
for p in bzrlib.plugin.all_plugins:
86
if hasattr(p, 'test_suite'):
87
suite.addTest(p.test_suite())
89
suite.addTest(unittest.makeSuite(bzrlib.merge_core.MergeTest, 'test_'))
91
return run_suite(suite, 'testbzr')
893
for name, plugin in bzrlib.plugin.all_plugins().items():
894
if getattr(plugin, 'test_suite', None) is not None:
895
suite.addTest(plugin.test_suite())
899
def adapt_modules(mods_list, adapter, loader, suite):
900
"""Adapt the modules in mods_list using adapter and add to suite."""
901
for mod_name in mods_list:
902
mod = _load_module_by_name(mod_name)
903
for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
904
suite.addTests(adapter.adapt(test))
907
def _load_module_by_name(mod_name):
908
parts = mod_name.split('.')
909
module = __import__(mod_name)
911
# for historical reasons python returns the top-level module even though
912
# it loads the submodule; we need to walk down to get the one we want.
914
module = getattr(module, parts.pop(0))