~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Martin Pool
  • Date: 2007-06-26 08:02:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2555.
  • Revision ID: mbp@sourcefrog.net-20070626080236-14ihgomtffc9tezj
Cleanup old variations on run_bzr in the test suite

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from pprint import pformat
38
38
import random
39
39
import re
 
40
import shlex
40
41
import stat
41
42
from subprocess import Popen, PIPE
42
43
import sys
76
77
from bzrlib.revision import common_ancestor
77
78
import bzrlib.store
78
79
from bzrlib import symbol_versioning
 
80
from bzrlib.symbol_versioning import (
 
81
    deprecated_method,
 
82
    zero_eighteen,
 
83
    )
79
84
import bzrlib.trace
80
85
from bzrlib.transport import get_transport
81
86
import bzrlib.transport
1193
1198
        else:
1194
1199
            return "DELETED log file to reduce memory footprint"
1195
1200
 
 
1201
    @deprecated_method(zero_eighteen)
1196
1202
    def capture(self, cmd, retcode=0):
1197
1203
        """Shortcut that splits cmd into words, runs, and returns stdout"""
1198
1204
        return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
1223
1229
        errors, and with logging set to something approximating the
1224
1230
        default, so that error reporting can be checked.
1225
1231
 
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
 
1232
        :param argv: Arguments to invoke bzr.  This may be either a 
 
1233
            single string, in which case it is split by shlex into words, 
 
1234
            or a list of arguments.
 
1235
        :param retcode: Expected return code, or None for don't-care.
 
1236
        :param encoding: Encoding for sys.stdout and sys.stderr
1229
1237
        :param stdin: A string to be used as stdin for the command.
1230
1238
        :param working_dir: Change to this directory before running
1231
1239
        """
1236
1244
        stdout.encoding = encoding
1237
1245
        stderr.encoding = encoding
1238
1246
 
 
1247
        if isinstance(argv, basestring):
 
1248
            argv = shlex.split(argv)
 
1249
        elif isinstance(argv, tuple):
 
1250
            if len(argv) == 1 and isinstance(argv[0], basestring):
 
1251
                argv = shlex.split(argv[0])
 
1252
 
1239
1253
        self.log('run bzr: %r', argv)
1240
1254
        # FIXME: don't call into logging here
1241
1255
        handler = logging.StreamHandler(stderr)
1284
1298
        overall behavior of the bzr application (rather than a unit test
1285
1299
        or a functional test of the library.)
1286
1300
 
1287
 
        This sends the stdout/stderr results into the test's log,
1288
 
        where it may be useful for debugging.  See also run_captured.
1289
 
 
1290
1301
        :param stdin: A string to be used as stdin for the command.
1291
1302
        :param retcode: The status code the command should return
1292
1303
        :param working_dir: The directory to run the command in
1297
1308
        working_dir = kwargs.pop('working_dir', None)
1298
1309
        error_regexes = kwargs.pop('error_regexes', [])
1299
1310
 
1300
 
        out, err = self.run_bzr_captured(args, retcode=retcode,
1301
 
            encoding=encoding, stdin=stdin, working_dir=working_dir)
 
1311
        if len(args) != 1:
 
1312
            warnings.warn("passing varargs to run_bzr is deprecated "
 
1313
                    "from bzr 0.18 onwards; please pass a list or "
 
1314
                    "string instead")
 
1315
 
 
1316
        out, err = self.run_bzr_captured(retcode=retcode,
 
1317
            encoding=encoding, stdin=stdin, working_dir=working_dir,
 
1318
            argv=args)
1302
1319
 
1303
1320
        for regex in error_regexes:
1304
1321
            self.assertContainsRe(err, regex)
1305
1322
        return out, err
1306
1323
 
1307
 
 
1308
1324
    def run_bzr_decode(self, *args, **kwargs):
1309
1325
        if 'encoding' in kwargs:
1310
1326
            encoding = kwargs['encoding']