73
76
bzrlib.tests.default_transport = old_transport
74
77
TestOptions.current_test = None
75
78
TestCaseInTempDir.TEST_ROOT = old_root
81
class TestRunBzr(ExternalBase):
83
def run_bzr_captured(self, argv, retcode=0, stdin=None):
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
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)
98
class TestRunBzrCaptured(ExternalBase):
100
def apply_redirected(self, stdin=None, stdout=None, stderr=None,
101
a_callable=None, *args, **kwargs):
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')
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)
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
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)