~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Robert Collins
  • Date: 2006-05-04 01:31:48 UTC
  • mto: (1697.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1701.
  • Revision ID: robertc@robertcollins.net-20060504013148-74208691b1b4857e
Add stdin parameter to run_bzr and run_bzr_captured.

Show diffs side-by-side

added added

removed removed

Lines of Context:
442
442
        """Shortcut that splits cmd into words, runs, and returns stdout"""
443
443
        return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
444
444
 
445
 
    def run_bzr_captured(self, argv, retcode=0):
 
445
    def run_bzr_captured(self, argv, retcode=0, stdin=None):
446
446
        """Invoke bzr and return (stdout, stderr).
447
447
 
448
448
        Useful for code that wants to check the contents of the
461
461
 
462
462
        argv -- arguments to invoke bzr
463
463
        retcode -- expected return code, or None for don't-care.
 
464
        :param stdin: A string to be used as stdin for the command.
464
465
        """
 
466
        if stdin is not None:
 
467
            stdin = StringIO(stdin)
465
468
        stdout = StringIO()
466
469
        stderr = StringIO()
467
470
        self.log('run bzr: %s', ' '.join(argv))
472
475
        logger = logging.getLogger('')
473
476
        logger.addHandler(handler)
474
477
        try:
475
 
            result = self.apply_redirected(None, stdout, stderr,
 
478
            result = self.apply_redirected(stdin, stdout, stderr,
476
479
                                           bzrlib.commands.run_bzr_catch_errors,
477
480
                                           argv)
478
481
        finally:
496
499
 
497
500
        This sends the stdout/stderr results into the test's log,
498
501
        where it may be useful for debugging.  See also run_captured.
 
502
 
 
503
        :param stdin: A string to be used as stdin for the command.
499
504
        """
500
505
        retcode = kwargs.pop('retcode', 0)
501
 
        return self.run_bzr_captured(args, retcode)
 
506
        stdin = kwargs.pop('stdin', None)
 
507
        return self.run_bzr_captured(args, retcode, stdin)
502
508
 
503
509
    def check_inventory_shape(self, inv, shape):
504
510
        """Compare an inventory to a list of expected names.