982
982
self.assertEqual(mode, actual_mode,
983
983
'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
985
def assertIsSameRealPath(self, path1, path2):
986
"""Fail if path1 and path2 points to different files"""
987
self.assertEqual(osutils.realpath(path1),
988
osutils.realpath(path2),
989
"apparent paths:\na = %s\nb = %s\n," % (path1, path2))
985
991
def assertIsInstance(self, obj, kls):
986
992
"""Fail if obj is not an instance of kls"""
987
993
if not isinstance(obj, kls):
1285
1291
return "DELETED log file to reduce memory footprint"
1287
@deprecated_method(zero_eighteen)
1288
def capture(self, cmd, retcode=0):
1289
"""Shortcut that splits cmd into words, runs, and returns stdout"""
1290
return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
1292
1293
def requireFeature(self, feature):
1293
1294
"""This test requires a specific feature is available.
1297
1298
if not feature.available():
1298
1299
raise UnavailableFeature(feature)
1300
@deprecated_method(zero_eighteen)
1301
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
1303
"""Invoke bzr and return (stdout, stderr).
1305
Don't call this method, just use run_bzr() which is equivalent.
1307
:param argv: Arguments to invoke bzr. This may be either a
1308
single string, in which case it is split by shlex into words,
1309
or a list of arguments.
1310
:param retcode: Expected return code, or None for don't-care.
1311
:param encoding: Encoding for sys.stdout and sys.stderr
1312
:param stdin: A string to be used as stdin for the command.
1313
:param working_dir: Change to this directory before running
1315
return self._run_bzr_autosplit(argv, retcode=retcode,
1316
encoding=encoding, stdin=stdin, working_dir=working_dir,
1319
1301
def _run_bzr_autosplit(self, args, retcode, encoding, stdin,
1321
1303
"""Run bazaar command line, splitting up a string command line."""
1354
1336
result = self.apply_redirected(ui.ui_factory.stdin,
1355
1337
stdout, stderr,
1356
bzrlib.commands.run_bzr_catch_errors,
1338
bzrlib.commands.run_bzr_catch_user_errors,
1359
1341
logger.removeHandler(handler)
1372
1354
message='Unexpected return code')
1373
1355
return out, err
1375
def run_bzr(self, *args, **kwargs):
1357
def run_bzr(self, args, retcode=0, encoding=None, stdin=None,
1358
working_dir=None, error_regexes=[], output_encoding=None):
1376
1359
"""Invoke bzr, as if it were run from the command line.
1378
1361
The argument list should not include the bzr program name - the
1386
1369
2- A single string, eg "add a". This is the most convenient
1387
1370
for hardcoded commands.
1389
3- Several varargs parameters, eg run_bzr("add", "a").
1390
This is not recommended for new code.
1392
1372
This runs bzr through the interface that catches and reports
1393
1373
errors, and with logging set to something approximating the
1394
1374
default, so that error reporting can be checked.
1407
1387
:keyword error_regexes: A list of expected error messages. If
1408
1388
specified they must be seen in the error output of the command.
1410
retcode = kwargs.pop('retcode', 0)
1411
encoding = kwargs.pop('encoding', None)
1412
stdin = kwargs.pop('stdin', None)
1413
working_dir = kwargs.pop('working_dir', None)
1414
error_regexes = kwargs.pop('error_regexes', [])
1417
raise TypeError("run_bzr() got unexpected keyword arguments '%s'"
1421
if isinstance(args[0], (list, basestring)):
1424
symbol_versioning.warn(zero_eighteen % "passing varargs to run_bzr",
1425
DeprecationWarning, stacklevel=3)
1427
out, err = self._run_bzr_autosplit(args=args,
1390
out, err = self._run_bzr_autosplit(
1428
1392
retcode=retcode,
1429
encoding=encoding, stdin=stdin, working_dir=working_dir,
1395
working_dir=working_dir,
1432
1397
for regex in error_regexes:
1433
1398
self.assertContainsRe(err, regex)
1434
1399
return out, err
1436
def run_bzr_decode(self, *args, **kwargs):
1437
if 'encoding' in kwargs:
1438
encoding = kwargs['encoding']
1440
encoding = bzrlib.user_encoding
1441
return self.run_bzr(*args, **kwargs)[0].decode(encoding)
1443
1401
def run_bzr_error(self, error_regexes, *args, **kwargs):
1444
1402
"""Run bzr, and check that stderr contains the supplied regexes