/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: John Arbash Meinel
  • Date: 2006-05-10 19:59:55 UTC
  • mfrom: (1704 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060510195955-df080afb1daa3a96
[merge] bzr.dev 1704

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import logging
34
34
import os
35
35
import re
36
 
import shutil
37
36
import stat
38
37
import sys
39
38
import tempfile
331
330
            raise AssertionError('string %r does not start with %r' % (s, prefix))
332
331
 
333
332
    def assertEndsWith(self, s, suffix):
334
 
        if not s.endswith(prefix):
 
333
        """Asserts that s ends with suffix."""
 
334
        if not s.endswith(suffix):
335
335
            raise AssertionError('string %r does not end with %r' % (s, suffix))
336
336
 
337
337
    def assertContainsRe(self, haystack, needle_re):
470
470
        """Shortcut that splits cmd into words, runs, and returns stdout"""
471
471
        return self.run_bzr_captured(cmd.split(), retcode=retcode)[0]
472
472
 
473
 
    def run_bzr_captured(self, argv, retcode=0, encoding=None):
 
473
    def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None):
474
474
        """Invoke bzr and return (stdout, stderr).
475
475
 
476
476
        Useful for code that wants to check the contents of the
490
490
        :param argv: arguments to invoke bzr
491
491
        :param retcode: expected return code, or None for don't-care.
492
492
        :param encoding: encoding for sys.stdout and sys.stderr
 
493
        :param stdin: A string to be used as stdin for the command.
493
494
        """
494
495
        if encoding is None:
495
496
            encoding = bzrlib.user_encoding
 
497
        if stdin is not None:
 
498
            stdin = StringIO(stdin)
496
499
        stdout = StringIOWrapper()
497
500
        stderr = StringIOWrapper()
498
501
        stdout.encoding = encoding
505
508
        handler.setLevel(logging.INFO)
506
509
        logger = logging.getLogger('')
507
510
        logger.addHandler(handler)
 
511
        old_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
 
512
        bzrlib.ui.ui_factory.stdin = stdin
508
513
        try:
509
 
            result = self.apply_redirected(None, stdout, stderr,
 
514
            result = self.apply_redirected(stdin, stdout, stderr,
510
515
                                           bzrlib.commands.run_bzr_catch_errors,
511
516
                                           argv)
512
517
        finally:
513
518
            logger.removeHandler(handler)
 
519
            bzrlib.ui.ui_factory.stdin = old_stdin
514
520
        # TODO: jam 20060105 Because we theoretically know the encoding
515
521
        #       of stdout and stderr, we could decode them at this time
516
522
        #       but for now, we will assume that the output of all
534
540
 
535
541
        This sends the stdout/stderr results into the test's log,
536
542
        where it may be useful for debugging.  See also run_captured.
 
543
 
 
544
        :param stdin: A string to be used as stdin for the command.
537
545
        """
538
546
        retcode = kwargs.pop('retcode', 0)
539
547
        encoding = kwargs.pop('encoding', None)
540
 
        return self.run_bzr_captured(args, retcode=retcode, encoding=encoding)
 
548
        stdin = kwargs.pop('stdin', None)
 
549
        return self.run_bzr_captured(args, retcode=retcode, encoding=encoding, stdin=stdin)
541
550
 
542
551
    def run_bzr_decode(self, *args, **kwargs):
543
552
        if kwargs.has_key('encoding'):
863
872
            # FIXME: make this use a single transport someday. RBC 20060418
864
873
            return format.initialize_on_transport(get_transport(relpath))
865
874
        except errors.UninitializableFormat:
866
 
            raise TestSkipped("Format %s is not initializable.")
 
875
            raise TestSkipped("Format %s is not initializable." % format)
867
876
 
868
877
    def make_repository(self, relpath, shared=False, format=None):
869
878
        """Create a repository on our default transport at relpath."""
955
964
        if test_root is not None:
956
965
            print 'Deleting test root %s...' % test_root
957
966
            try:
958
 
                shutil.rmtree(test_root)
 
967
                osutils.rmtree(test_root)
959
968
            finally:
960
969
                print
961
970
    else:
990
999
 
991
1000
    testmod_names = [ \
992
1001
                   'bzrlib.tests.test_ancestry',
993
 
                   'bzrlib.tests.test_annotate',
994
1002
                   'bzrlib.tests.test_api',
995
1003
                   'bzrlib.tests.test_bad_files',
996
1004
                   'bzrlib.tests.test_branch',