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
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
104
109
import bzrlib.tests.bzrdir_implementations
105
110
import bzrlib.tests.interrepository_implementations
106
111
import bzrlib.tests.interversionedfile_implementations
112
import bzrlib.tests.intertree_implementations
107
113
import bzrlib.tests.repository_implementations
108
114
import bzrlib.tests.revisionstore_implementations
115
import bzrlib.tests.tree_implementations
109
116
import bzrlib.tests.workingtree_implementations
114
121
bzrlib.tests.bzrdir_implementations,
115
122
bzrlib.tests.interrepository_implementations,
116
123
bzrlib.tests.interversionedfile_implementations,
124
bzrlib.tests.intertree_implementations,
117
125
bzrlib.tests.repository_implementations,
118
126
bzrlib.tests.revisionstore_implementations,
127
bzrlib.tests.tree_implementations,
119
128
bzrlib.tests.workingtree_implementations,
214
223
self.stream.write('E')
216
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()))
217
229
self.stream.flush()
218
230
if self.stop_early:
227
239
self.stream.write('F')
229
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()))
230
245
self.stream.flush()
231
246
if self.stop_early:
257
272
self.stream.flush()
258
273
# seems best to treat this as success from point-of-view of unittest
259
274
# -- it actually does nothing so it barely matters :)
260
unittest.TestResult.addSuccess(self, test)
277
except KeyboardInterrupt:
280
self.addError(test, test.__exc_info())
282
unittest.TestResult.addSuccess(self, test)
262
284
def printErrorList(self, flavour, errors):
263
285
for test, err in errors:
334
356
# If LANG=C we probably have created some bogus paths
335
357
# which rmtree(unicode) will fail to delete
336
358
# so make sure we are using rmtree(str) to delete everything
337
osutils.rmtree(test_root.encode(
338
sys.getfilesystemencoding()))
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)
340
370
if self.pb is not None:
341
371
self.pb.note("Failed tests working directories are in '%s'\n",
484
514
raise AssertionError('pattern "%s" not found in "%s"'
485
515
% (needle_re, haystack))
517
def assertNotContainsRe(self, haystack, needle_re):
518
"""Assert that a does not match a regular expression"""
519
if re.search(needle_re, haystack):
520
raise AssertionError('pattern "%s" found in "%s"'
521
% (needle_re, haystack))
487
523
def assertSubset(self, sublist, superlist):
488
524
"""Assert that every entry in sublist is present in superlist."""
534
570
Read contents into memory, close, and delete.
572
if self._log_file is None:
536
574
bzrlib.trace.disable_test_log(self._log_nonce)
537
575
self._log_file.seek(0)
538
576
self._log_contents = self._log_file.read()
670
708
self.log('run bzr: %r', argv)
671
709
# FIXME: don't call into logging here
672
710
handler = logging.StreamHandler(stderr)
673
handler.setFormatter(bzrlib.trace.QuietFormatter())
674
711
handler.setLevel(logging.INFO)
675
712
logger = logging.getLogger('')
676
713
logger.addHandler(handler)
721
758
encoding = bzrlib.user_encoding
722
759
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
761
def run_bzr_error(self, error_regexes, *args, **kwargs):
762
"""Run bzr, and check that stderr contains the supplied regexes
764
:param error_regexes: Sequence of regular expressions which
765
must each be found in the error output. The relative ordering
767
:param args: command-line arguments for bzr
768
:param kwargs: Keyword arguments which are interpreted by run_bzr
769
This function changes the default value of retcode to be 3,
770
since in most cases this is run when you expect bzr to fail.
771
:return: (out, err) The actual output of running the command (in case you
772
want to do more inspection)
775
# Make sure that commit is failing because there is nothing to do
776
self.run_bzr_error(['no changes to commit'],
777
'commit', '-m', 'my commit comment')
778
# Make sure --strict is handling an unknown file, rather than
779
# giving us the 'nothing to do' error
780
self.build_tree(['unknown'])
781
self.run_bzr_error(['Commit refused because there are unknown files'],
782
'commit', '--strict', '-m', 'my commit comment')
784
kwargs.setdefault('retcode', 3)
785
out, err = self.run_bzr(*args, **kwargs)
786
for regex in error_regexes:
787
self.assertContainsRe(err, regex)
724
790
def run_bzr_subprocess(self, *args, **kwargs):
725
791
"""Run bzr in a subprocess for testing.
729
795
this isolation: e.g. they are testing startup time, or signal
730
796
handling, or early startup code, etc. Subprocess code can't be
731
797
profiled or debugged so easily.
799
:param retcode: The status code that is expected. Defaults to 0. If
800
None is supplied, the status code is not checked.
733
802
bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
735
args = shlex.split(args[0])
736
803
args = list(args)
737
804
process = Popen([sys.executable, bzr_path]+args, stdout=PIPE,
1124
1191
def filter_suite_by_re(suite, pattern):
1125
result = TestSuite()
1192
result = TestUtil.TestSuite()
1126
1193
filter_re = re.compile(pattern)
1127
1194
for test in iter_suite_tests(suite):
1128
1195
if filter_re.search(test.id()):
1183
1250
This function can be replaced if you need to change the default test
1184
1251
suite on a global basis, but it is not encouraged.
1186
from doctest import DocTestSuite
1188
global MODULES_TO_DOCTEST
1191
1254
'bzrlib.tests.test_ancestry',
1192
1255
'bzrlib.tests.test_api',
1193
1256
'bzrlib.tests.test_bad_files',
1209
1272
'bzrlib.tests.test_graph',
1210
1273
'bzrlib.tests.test_hashcache',
1211
1274
'bzrlib.tests.test_http',
1275
'bzrlib.tests.test_http_response',
1212
1276
'bzrlib.tests.test_identitymap',
1277
'bzrlib.tests.test_ignores',
1213
1278
'bzrlib.tests.test_inv',
1214
1279
'bzrlib.tests.test_knit',
1215
1280
'bzrlib.tests.test_lockdir',
1232
1297
'bzrlib.tests.test_repository',
1233
1298
'bzrlib.tests.test_revision',
1234
1299
'bzrlib.tests.test_revisionnamespaces',
1235
'bzrlib.tests.test_revprops',
1300
'bzrlib.tests.test_revisiontree',
1236
1301
'bzrlib.tests.test_rio',
1237
1302
'bzrlib.tests.test_sampler',
1238
1303
'bzrlib.tests.test_selftest',
1250
1315
'bzrlib.tests.test_transactions',
1251
1316
'bzrlib.tests.test_transform',
1252
1317
'bzrlib.tests.test_transport',
1318
'bzrlib.tests.test_tree',
1253
1319
'bzrlib.tests.test_tsort',
1254
1320
'bzrlib.tests.test_tuned_gzip',
1255
1321
'bzrlib.tests.test_ui',
1262
1328
'bzrlib.tests.test_xml',
1264
1330
test_transport_implementations = [
1265
'bzrlib.tests.test_transport_implementations']
1331
'bzrlib.tests.test_transport_implementations',
1332
'bzrlib.tests.test_read_bundle',
1334
suite = TestUtil.TestSuite()
1268
1335
loader = TestUtil.TestLoader()
1336
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1269
1337
from bzrlib.transport import TransportTestProviderAdapter
1270
1338
adapter = TransportTestProviderAdapter()
1271
1339
adapt_modules(test_transport_implementations, adapter, loader, suite)
1272
suite.addTest(loader.loadTestsFromModuleNames(testmod_names))
1273
1340
for package in packages_to_test():
1274
1341
suite.addTest(package.test_suite())
1275
1342
for m in MODULES_TO_TEST:
1276
1343
suite.addTest(loader.loadTestsFromModule(m))
1277
for m in (MODULES_TO_DOCTEST):
1278
suite.addTest(DocTestSuite(m))
1344
for m in MODULES_TO_DOCTEST:
1345
suite.addTest(doctest.DocTestSuite(m))
1279
1346
for name, plugin in bzrlib.plugin.all_plugins().items():
1280
1347
if getattr(plugin, 'test_suite', None) is not None:
1281
1348
suite.addTest(plugin.test_suite())