~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_selftest.py

Update test support, and remove deprecated functions pullable_revisions and get_intervening_revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""UI tests for the test framework."""
17
17
 
 
18
import sys
 
19
 
18
20
import bzrlib
19
21
from bzrlib.errors import ParamikoNotPresent
20
22
from bzrlib.tests import (
22
24
                          TestCaseInTempDir,
23
25
                          TestSkipped,
24
26
                          )
 
27
from bzrlib.tests.blackbox import ExternalBase
25
28
 
26
29
 
27
30
class TestOptions(TestCase):
73
76
            bzrlib.tests.default_transport = old_transport
74
77
            TestOptions.current_test = None
75
78
            TestCaseInTempDir.TEST_ROOT = old_root
 
79
 
 
80
 
 
81
class TestRunBzr(ExternalBase):
 
82
 
 
83
    def run_bzr_captured(self, argv, retcode=0, stdin=None):
 
84
        self.stdin = stdin
 
85
 
 
86
    def test_stdin(self):
 
87
        # test that the stdin keyword to run_bzr is passed through to
 
88
        # run_bzr_captured as-is. We do this by overriding
 
89
        # run_bzr_captured in this class, and then calling run_bzr,
 
90
        # which is a convenience function for run_bzr_captured, so 
 
91
        # should invoke it.
 
92
        self.run_bzr('foo', 'bar', stdin='gam')
 
93
        self.assertEqual('gam', self.stdin)
 
94
        self.run_bzr('foo', 'bar', stdin='zippy')
 
95
        self.assertEqual('zippy', self.stdin)
 
96
 
 
97
 
 
98
class TestRunBzrCaptured(ExternalBase):
 
99
 
 
100
    def apply_redirected(self, stdin=None, stdout=None, stderr=None,
 
101
                         a_callable=None, *args, **kwargs):
 
102
        self.stdin = stdin
 
103
        self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
 
104
        self.factory = bzrlib.ui.ui_factory
 
105
        stdout.write('foo\n')
 
106
        stderr.write('bar\n')
 
107
        return 0
 
108
 
 
109
    def test_stdin(self):
 
110
        # test that the stdin keyword to run_bzr_captured is passed through to
 
111
        # apply_redirected as a StringIO. We do this by overriding
 
112
        # apply_redirected in this class, and then calling run_bzr_captured,
 
113
        # which calls apply_redirected. 
 
114
        self.run_bzr_captured(['foo', 'bar'], stdin='gam')
 
115
        self.assertEqual('gam', self.stdin.read())
 
116
        self.assertTrue(self.stdin is self.factory_stdin)
 
117
        self.run_bzr_captured(['foo', 'bar'], stdin='zippy')
 
118
        self.assertEqual('zippy', self.stdin.read())
 
119
        self.assertTrue(self.stdin is self.factory_stdin)
 
120
 
 
121
    def test_ui_factory(self):
 
122
        # each invocation of self.run_bzr_captured should get its own UI
 
123
        # factory, which is an instance of TestUIFactory, with stdout and
 
124
        # stderr attached to the stdout and stderr of the invoked
 
125
        # run_bzr_captured
 
126
        current_factory = bzrlib.ui.ui_factory
 
127
        self.run_bzr_captured(['foo'])
 
128
        self.failIf(current_factory is self.factory)
 
129
        self.assertNotEqual(sys.stdout, self.factory.stdout)
 
130
        self.assertNotEqual(sys.stderr, self.factory.stderr)
 
131
        self.assertEqual('foo\n', self.factory.stdout.getvalue())
 
132
        self.assertEqual('bar\n', self.factory.stderr.getvalue())
 
133
        self.assertIsInstance(self.factory, bzrlib.tests.blackbox.TestUIFactory)