69
70
from bzrlib.transport.local import LocalRelpathServer
70
71
from bzrlib.transport.readonly import ReadonlyServer
71
72
from bzrlib.trace import mutter
72
from bzrlib.tests.TestUtil import TestLoader, TestSuite
73
from bzrlib.tests import TestUtil
74
from bzrlib.tests.TestUtil import (
73
78
from bzrlib.tests.treeshape import build_tree_contents
74
79
import bzrlib.urlutils as urlutils
75
80
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
257
268
self.stream.flush()
258
269
# seems best to treat this as success from point-of-view of unittest
259
270
# -- it actually does nothing so it barely matters :)
260
unittest.TestResult.addSuccess(self, test)
273
except KeyboardInterrupt:
276
self.addError(test, test.__exc_info())
278
unittest.TestResult.addSuccess(self, test)
262
280
def printErrorList(self, flavour, errors):
263
281
for test, err in errors:
334
352
# If LANG=C we probably have created some bogus paths
335
353
# which rmtree(unicode) will fail to delete
336
354
# so make sure we are using rmtree(str) to delete everything
337
osutils.rmtree(test_root.encode(
338
sys.getfilesystemencoding()))
355
# except on win32, where rmtree(str) will fail
356
# since it doesn't have the property of byte-stream paths
357
# (they are either ascii or mbcs)
358
if sys.platform == 'win32':
359
# make sure we are using the unicode win32 api
360
test_root = unicode(test_root)
362
test_root = test_root.encode(
363
sys.getfilesystemencoding())
364
osutils.rmtree(test_root)
340
366
if self.pb is not None:
341
367
self.pb.note("Failed tests working directories are in '%s'\n",
484
510
raise AssertionError('pattern "%s" not found in "%s"'
485
511
% (needle_re, haystack))
513
def assertNotContainsRe(self, haystack, needle_re):
514
"""Assert that a does not match a regular expression"""
515
if re.search(needle_re, haystack):
516
raise AssertionError('pattern "%s" found in "%s"'
517
% (needle_re, haystack))
487
519
def assertSubset(self, sublist, superlist):
488
520
"""Assert that every entry in sublist is present in superlist."""
721
754
encoding = bzrlib.user_encoding
722
755
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
724
def run_bzr_external(self, *args, **kwargs):
757
def run_bzr_error(self, error_regexes, *args, **kwargs):
758
"""Run bzr, and check that stderr contains the supplied regexes
760
:param error_regexes: Sequence of regular expressions which
761
must each be found in the error output. The relative ordering
763
:param args: command-line arguments for bzr
764
:param kwargs: Keyword arguments which are interpreted by run_bzr
765
This function changes the default value of retcode to be 3,
766
since in most cases this is run when you expect bzr to fail.
767
:return: (out, err) The actual output of running the command (in case you
768
want to do more inspection)
771
# Make sure that commit is failing because there is nothing to do
772
self.run_bzr_error(['no changes to commit'],
773
'commit', '-m', 'my commit comment')
774
# Make sure --strict is handling an unknown file, rather than
775
# giving us the 'nothing to do' error
776
self.build_tree(['unknown'])
777
self.run_bzr_error(['Commit refused because there are unknown files'],
778
'commit', '--strict', '-m', 'my commit comment')
780
kwargs.setdefault('retcode', 3)
781
out, err = self.run_bzr(*args, **kwargs)
782
for regex in error_regexes:
783
self.assertContainsRe(err, regex)
786
def run_bzr_subprocess(self, *args, **kwargs):
787
"""Run bzr in a subprocess for testing.
789
This starts a new Python interpreter and runs bzr in there.
790
This should only be used for tests that have a justifiable need for
791
this isolation: e.g. they are testing startup time, or signal
792
handling, or early startup code, etc. Subprocess code can't be
793
profiled or debugged so easily.
795
:param retcode: The status code that is expected. Defaults to 0. If
796
None is supplied, the status code is not checked.
725
798
bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
727
args = shlex.split(args[0])
728
799
args = list(args)
729
process = Popen([bzr_path]+args, stdout=PIPE, stderr=PIPE)
800
process = Popen([sys.executable, bzr_path]+args, stdout=PIPE,
730
802
out = process.stdout.read()
731
803
err = process.stderr.read()
732
804
retcode = process.wait()
733
supplied_retcode = kwargs.get('retcode')
805
supplied_retcode = kwargs.get('retcode', 0)
734
806
if supplied_retcode is not None:
735
807
assert supplied_retcode == retcode
738
808
return [out, err]
740
810
def check_inventory_shape(self, inv, shape):
1194
1260
'bzrlib.tests.test_commit_merge',
1195
1261
'bzrlib.tests.test_config',
1196
1262
'bzrlib.tests.test_conflicts',
1263
'bzrlib.tests.test_delta',
1197
1264
'bzrlib.tests.test_decorators',
1198
1265
'bzrlib.tests.test_diff',
1199
1266
'bzrlib.tests.test_doc_generate',
1204
1271
'bzrlib.tests.test_graph',
1205
1272
'bzrlib.tests.test_hashcache',
1206
1273
'bzrlib.tests.test_http',
1274
'bzrlib.tests.test_http_response',
1207
1275
'bzrlib.tests.test_identitymap',
1276
'bzrlib.tests.test_ignores',
1208
1277
'bzrlib.tests.test_inv',
1209
1278
'bzrlib.tests.test_knit',
1210
1279
'bzrlib.tests.test_lockdir',
1257
1327
'bzrlib.tests.test_xml',
1259
1329
test_transport_implementations = [
1260
'bzrlib.tests.test_transport_implementations']
1330
'bzrlib.tests.test_transport_implementations',
1331
'bzrlib.tests.test_read_bundle',
1333
suite = TestUtil.TestSuite()
1263
1334
loader = TestUtil.TestLoader()
1335
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1264
1336
from bzrlib.transport import TransportTestProviderAdapter
1265
1337
adapter = TransportTestProviderAdapter()
1266
1338
adapt_modules(test_transport_implementations, adapter, loader, suite)
1267
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1268
1339
for package in packages_to_test():
1269
1340
suite.addTest(package.test_suite())
1270
1341
for m in MODULES_TO_TEST:
1271
1342
suite.addTest(loader.loadTestsFromModule(m))
1272
for m in (MODULES_TO_DOCTEST):
1273
suite.addTest(DocTestSuite(m))
1343
for m in MODULES_TO_DOCTEST:
1344
suite.addTest(doctest.DocTestSuite(m))
1274
1345
for name, plugin in bzrlib.plugin.all_plugins().items():
1275
1346
if getattr(plugin, 'test_suite', None) is not None:
1276
1347
suite.addTest(plugin.test_suite())