/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Alexander Belchenko
  • Date: 2007-10-04 05:50:44 UTC
  • mfrom: (2881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2884.
  • Revision ID: bialix@ukr.net-20071004055044-pb88kgkfayawro8n
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
from bzrlib import symbol_versioning
79
79
from bzrlib.symbol_versioning import (
80
80
    deprecated_method,
81
 
    zero_eighteen,
82
81
    zero_ninetyone,
 
82
    zero_ninetytwo,
83
83
    )
84
84
import bzrlib.trace
85
85
from bzrlib.transport import get_transport
982
982
        self.assertEqual(mode, actual_mode,
983
983
            'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
984
984
 
 
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))
 
990
 
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):
1284
1290
        else:
1285
1291
            return "DELETED log file to reduce memory footprint"
1286
1292
 
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]
1291
 
 
1292
1293
    def requireFeature(self, feature):
1293
1294
        """This test requires a specific feature is available.
1294
1295
 
1297
1298
        if not feature.available():
1298
1299
            raise UnavailableFeature(feature)
1299
1300
 
1300
 
    @deprecated_method(zero_eighteen)
1301
 
    def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
1302
 
                         working_dir=None):
1303
 
        """Invoke bzr and return (stdout, stderr).
1304
 
 
1305
 
        Don't call this method, just use run_bzr() which is equivalent.
1306
 
 
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
1314
 
        """
1315
 
        return self._run_bzr_autosplit(argv, retcode=retcode,
1316
 
                encoding=encoding, stdin=stdin, working_dir=working_dir,
1317
 
                )
1318
 
 
1319
1301
    def _run_bzr_autosplit(self, args, retcode, encoding, stdin,
1320
1302
            working_dir):
1321
1303
        """Run bazaar command line, splitting up a string command line."""
1353
1335
        try:
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,
1357
1339
                args)
1358
1340
        finally:
1359
1341
            logger.removeHandler(handler)
1372
1354
                              message='Unexpected return code')
1373
1355
        return out, err
1374
1356
 
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.
1377
1360
 
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.
1388
1371
 
1389
 
        3- Several varargs parameters, eg run_bzr("add", "a").  
1390
 
        This is not recommended for new code.
1391
 
 
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.
1409
1389
        """
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', [])
1415
 
 
1416
 
        if kwargs:
1417
 
            raise TypeError("run_bzr() got unexpected keyword arguments '%s'"
1418
 
                            % kwargs.keys())
1419
 
 
1420
 
        if len(args) == 1:
1421
 
            if isinstance(args[0], (list, basestring)):
1422
 
                args = args[0]
1423
 
        else:
1424
 
            symbol_versioning.warn(zero_eighteen % "passing varargs to run_bzr",
1425
 
                                   DeprecationWarning, stacklevel=3)
1426
 
 
1427
 
        out, err = self._run_bzr_autosplit(args=args,
 
1390
        out, err = self._run_bzr_autosplit(
 
1391
            args=args,
1428
1392
            retcode=retcode,
1429
 
            encoding=encoding, stdin=stdin, working_dir=working_dir,
 
1393
            encoding=encoding,
 
1394
            stdin=stdin,
 
1395
            working_dir=working_dir,
1430
1396
            )
1431
 
 
1432
1397
        for regex in error_regexes:
1433
1398
            self.assertContainsRe(err, regex)
1434
1399
        return out, err
1435
1400
 
1436
 
    def run_bzr_decode(self, *args, **kwargs):
1437
 
        if 'encoding' in kwargs:
1438
 
            encoding = kwargs['encoding']
1439
 
        else:
1440
 
            encoding = bzrlib.user_encoding
1441
 
        return self.run_bzr(*args, **kwargs)[0].decode(encoding)
1442
 
 
1443
1401
    def run_bzr_error(self, error_regexes, *args, **kwargs):
1444
1402
        """Run bzr, and check that stderr contains the supplied regexes
1445
1403