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
262
self.stream.flush()
258
263
# seems best to treat this as success from point-of-view of unittest
259
264
# -- it actually does nothing so it barely matters :)
260
unittest.TestResult.addSuccess(self, test)
267
except KeyboardInterrupt:
270
self.addError(test, test.__exc_info())
272
unittest.TestResult.addSuccess(self, test)
262
274
def printErrorList(self, flavour, errors):
263
275
for test, err in errors:
334
346
# If LANG=C we probably have created some bogus paths
335
347
# which rmtree(unicode) will fail to delete
336
348
# so make sure we are using rmtree(str) to delete everything
337
osutils.rmtree(test_root.encode(
338
sys.getfilesystemencoding()))
349
# except on win32, where rmtree(str) will fail
350
# since it doesn't have the property of byte-stream paths
351
# (they are either ascii or mbcs)
352
if sys.platform == 'win32':
353
# make sure we are using the unicode win32 api
354
test_root = unicode(test_root)
356
test_root = test_root.encode(
357
sys.getfilesystemencoding())
358
osutils.rmtree(test_root)
340
360
if self.pb is not None:
341
361
self.pb.note("Failed tests working directories are in '%s'\n",
540
560
Read contents into memory, close, and delete.
562
if self._log_file is None:
542
564
bzrlib.trace.disable_test_log(self._log_nonce)
543
565
self._log_file.seek(0)
544
566
self._log_contents = self._log_file.read()
676
698
self.log('run bzr: %r', argv)
677
699
# FIXME: don't call into logging here
678
700
handler = logging.StreamHandler(stderr)
679
handler.setFormatter(bzrlib.trace.QuietFormatter())
680
701
handler.setLevel(logging.INFO)
681
702
logger = logging.getLogger('')
682
703
logger.addHandler(handler)
727
748
encoding = bzrlib.user_encoding
728
749
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
751
def run_bzr_error(self, error_regexes, *args, **kwargs):
752
"""Run bzr, and check that stderr contains the supplied regexes
754
:param error_regexes: Sequence of regular expressions which
755
must each be found in the error output. The relative ordering
757
:param args: command-line arguments for bzr
758
:param kwargs: Keyword arguments which are interpreted by run_bzr
759
This function changes the default value of retcode to be 3,
760
since in most cases this is run when you expect bzr to fail.
761
:return: (out, err) The actual output of running the command (in case you
762
want to do more inspection)
765
# Make sure that commit is failing because there is nothing to do
766
self.run_bzr_error(['no changes to commit'],
767
'commit', '-m', 'my commit comment')
768
# Make sure --strict is handling an unknown file, rather than
769
# giving us the 'nothing to do' error
770
self.build_tree(['unknown'])
771
self.run_bzr_error(['Commit refused because there are unknown files'],
772
'commit', '--strict', '-m', 'my commit comment')
774
kwargs.setdefault('retcode', 3)
775
out, err = self.run_bzr(*args, **kwargs)
776
for regex in error_regexes:
777
self.assertContainsRe(err, regex)
730
780
def run_bzr_subprocess(self, *args, **kwargs):
731
781
"""Run bzr in a subprocess for testing.
1131
1181
def filter_suite_by_re(suite, pattern):
1132
result = TestSuite()
1182
result = TestUtil.TestSuite()
1133
1183
filter_re = re.compile(pattern)
1134
1184
for test in iter_suite_tests(suite):
1135
1185
if filter_re.search(test.id()):
1190
1240
This function can be replaced if you need to change the default test
1191
1241
suite on a global basis, but it is not encouraged.
1193
from doctest import DocTestSuite
1195
global MODULES_TO_DOCTEST
1198
1244
'bzrlib.tests.test_ancestry',
1199
1245
'bzrlib.tests.test_api',
1200
1246
'bzrlib.tests.test_bad_files',
1274
1320
'bzrlib.tests.test_transport_implementations',
1275
1321
'bzrlib.tests.test_read_bundle',
1323
suite = TestUtil.TestSuite()
1279
1324
loader = TestUtil.TestLoader()
1280
1325
from bzrlib.transport import TransportTestProviderAdapter
1281
1326
adapter = TransportTestProviderAdapter()
1285
1330
suite.addTest(package.test_suite())
1286
1331
for m in MODULES_TO_TEST:
1287
1332
suite.addTest(loader.loadTestsFromModule(m))
1288
for m in (MODULES_TO_DOCTEST):
1289
suite.addTest(DocTestSuite(m))
1333
for m in MODULES_TO_DOCTEST:
1334
suite.addTest(doctest.DocTestSuite(m))
1290
1335
for name, plugin in bzrlib.plugin.all_plugins().items():
1291
1336
if getattr(plugin, 'test_suite', None) is not None:
1292
1337
suite.addTest(plugin.test_suite())