~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-05-05 08:29:29 UTC
  • mfrom: (1697.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060505082929-a037ee137f1ff240
Merge break-lock command.

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))
471
474
        handler.setLevel(logging.INFO)
472
475
        logger = logging.getLogger('')
473
476
        logger.addHandler(handler)
 
477
        old_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
 
478
        bzrlib.ui.ui_factory.stdin = stdin
474
479
        try:
475
 
            result = self.apply_redirected(None, stdout, stderr,
 
480
            result = self.apply_redirected(stdin, stdout, stderr,
476
481
                                           bzrlib.commands.run_bzr_catch_errors,
477
482
                                           argv)
478
483
        finally:
479
484
            logger.removeHandler(handler)
 
485
            bzrlib.ui.ui_factory.stdin = old_stdin
480
486
        out = stdout.getvalue()
481
487
        err = stderr.getvalue()
482
488
        if out:
496
502
 
497
503
        This sends the stdout/stderr results into the test's log,
498
504
        where it may be useful for debugging.  See also run_captured.
 
505
 
 
506
        :param stdin: A string to be used as stdin for the command.
499
507
        """
500
508
        retcode = kwargs.pop('retcode', 0)
501
 
        return self.run_bzr_captured(args, retcode)
 
509
        stdin = kwargs.pop('stdin', None)
 
510
        return self.run_bzr_captured(args, retcode, stdin)
502
511
 
503
512
    def check_inventory_shape(self, inv, shape):
504
513
        """Compare an inventory to a list of expected names.