984
989
def applyDeprecated(self, deprecation_format, a_callable, *args, **kwargs):
985
990
"""Call a deprecated callable without warning the user.
992
Note that this only captures warnings raised by symbol_versioning.warn,
993
not other callers that go direct to the warning module.
987
995
:param deprecation_format: The deprecation format that the callable
988
996
should have been deprecated with. This is the same type as the
989
997
parameter to deprecated_method/deprecated_function. If the
1013
1021
as it allows you to simply specify the deprecation format being used
1014
1022
and will ensure that that is issued for the function being called.
1024
Note that this only captures warnings raised by symbol_versioning.warn,
1025
not other callers that go direct to the warning module.
1016
1027
:param expected: a list of the deprecation warnings expected, in order
1017
1028
:param callable: The callable to call
1018
1029
:param args: The positional arguments for the callable
1205
1217
if not feature.available():
1206
1218
raise UnavailableFeature(feature)
1220
@deprecated_method(zero_eighteen)
1208
1221
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
1209
1222
working_dir=None):
1210
1223
"""Invoke bzr and return (stdout, stderr).
1212
Useful for code that wants to check the contents of the
1213
output, the way error messages are presented, etc.
1215
This should be the main method for tests that want to exercise the
1216
overall behavior of the bzr application (rather than a unit test
1217
or a functional test of the library.)
1219
Much of the old code runs bzr by forking a new copy of Python, but
1220
that is slower, harder to debug, and generally not necessary.
1222
This runs bzr through the interface that catches and reports
1223
errors, and with logging set to something approximating the
1224
default, so that error reporting can be checked.
1226
:param argv: arguments to invoke bzr
1227
:param retcode: expected return code, or None for don't-care.
1228
:param encoding: encoding for sys.stdout and sys.stderr
1225
Don't call this method, just use run_bzr() which is equivalent.
1227
:param argv: Arguments to invoke bzr. This may be either a
1228
single string, in which case it is split by shlex into words,
1229
or a list of arguments.
1230
:param retcode: Expected return code, or None for don't-care.
1231
:param encoding: Encoding for sys.stdout and sys.stderr
1229
1232
:param stdin: A string to be used as stdin for the command.
1230
1233
:param working_dir: Change to this directory before running
1235
return self._run_bzr_autosplit(argv, retcode=retcode,
1236
encoding=encoding, stdin=stdin, working_dir=working_dir,
1239
def _run_bzr_autosplit(self, args, retcode, encoding, stdin,
1241
"""Run bazaar command line, splitting up a string command line."""
1242
if isinstance(args, basestring):
1243
args = list(shlex.split(args))
1244
return self._run_bzr_core(args, retcode=retcode,
1245
encoding=encoding, stdin=stdin, working_dir=working_dir,
1248
def _run_bzr_core(self, args, retcode, encoding, stdin,
1232
1250
if encoding is None:
1233
1251
encoding = bzrlib.user_encoding
1234
1252
stdout = StringIOWrapper()
1236
1254
stdout.encoding = encoding
1237
1255
stderr.encoding = encoding
1239
self.log('run bzr: %r', argv)
1257
self.log('run bzr: %r', args)
1240
1258
# FIXME: don't call into logging here
1241
1259
handler = logging.StreamHandler(stderr)
1242
1260
handler.setLevel(logging.INFO)
1280
1298
def run_bzr(self, *args, **kwargs):
1281
1299
"""Invoke bzr, as if it were run from the command line.
1301
The argument list should not include the bzr program name - the
1302
first argument is normally the bzr command. Arguments may be
1303
passed in three ways:
1305
1- A list of strings, eg ["commit", "a"]. This is recommended
1306
when the command contains whitespace or metacharacters, or
1307
is built up at run time.
1309
2- A single string, eg "add a". This is the most convenient
1310
for hardcoded commands.
1312
3- Several varargs parameters, eg run_bzr("add", "a").
1313
This is not recommended for new code.
1315
This runs bzr through the interface that catches and reports
1316
errors, and with logging set to something approximating the
1317
default, so that error reporting can be checked.
1283
1319
This should be the main method for tests that want to exercise the
1284
1320
overall behavior of the bzr application (rather than a unit test
1285
1321
or a functional test of the library.)
1287
This sends the stdout/stderr results into the test's log,
1288
where it may be useful for debugging. See also run_captured.
1290
1323
:param stdin: A string to be used as stdin for the command.
1291
:param retcode: The status code the command should return
1324
:param retcode: The status code the command should return;
1292
1326
:param working_dir: The directory to run the command in
1327
:param error_regexes: A list of expected error messages. If
1328
specified they must be seen in the error output of the command.
1294
1330
retcode = kwargs.pop('retcode', 0)
1295
1331
encoding = kwargs.pop('encoding', None)
1297
1333
working_dir = kwargs.pop('working_dir', None)
1298
1334
error_regexes = kwargs.pop('error_regexes', [])
1300
out, err = self.run_bzr_captured(args, retcode=retcode,
1301
encoding=encoding, stdin=stdin, working_dir=working_dir)
1337
if isinstance(args[0], (list, basestring)):
1340
## symbol_versioning.warn(zero_eighteen % "passing varargs to run_bzr",
1341
## DeprecationWarning, stacklevel=2)
1342
# not done yet, because too many tests would need to be updated -
1343
# but please don't do this in new code. -- mbp 20070626
1346
out, err = self._run_bzr_autosplit(args=args,
1348
encoding=encoding, stdin=stdin, working_dir=working_dir,
1303
1351
for regex in error_regexes:
1304
1352
self.assertContainsRe(err, regex)
1305
1353
return out, err
1308
1355
def run_bzr_decode(self, *args, **kwargs):
1309
1356
if 'encoding' in kwargs:
1310
1357
encoding = kwargs['encoding']
1532
1579
sys.stderr = real_stderr
1533
1580
sys.stdin = real_stdin
1535
@symbol_versioning.deprecated_method(symbol_versioning.zero_eleven)
1536
def merge(self, branch_from, wt_to):
1537
"""A helper for tests to do a ui-less merge.
1539
This should move to the main library when someone has time to integrate
1542
# minimal ui-less merge.
1543
wt_to.branch.fetch(branch_from)
1544
base_rev = common_ancestor(branch_from.last_revision(),
1545
wt_to.branch.last_revision(),
1546
wt_to.branch.repository)
1547
merge_inner(wt_to.branch, branch_from.basis_tree(),
1548
wt_to.branch.repository.revision_tree(base_rev),
1550
wt_to.add_parent_tree_id(branch_from.last_revision())
1552
1582
def reduceLockdirTimeout(self):
1553
1583
"""Reduce the default lock timeout for the duration of the test, so that
1554
1584
if LockContention occurs during a test, it does so quickly.
2299
2327
'bzrlib.tests.test_smart',
2300
2328
'bzrlib.tests.test_smart_add',
2301
2329
'bzrlib.tests.test_smart_transport',
2330
'bzrlib.tests.test_smtp_connection',
2302
2331
'bzrlib.tests.test_source',
2303
2332
'bzrlib.tests.test_ssh_transport',
2304
2333
'bzrlib.tests.test_status',