87
87
class TestRunBzr(ExternalBase):
89
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None):
89
def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
91
"""Override run_bzr_captured to test how it is invoked by run_bzr.
93
We test how run_bzr_captured actually invokes bzr in another location.
94
Here we only need to test that it is run_bzr passes the right
95
parameters to run_bzr_captured.
98
self.retcode = retcode
99
self.encoding = encoding
90
100
self.stdin = stdin
101
self.working_dir = working_dir
104
"""Test that run_bzr passes args correctly to run_bzr_captured"""
105
self.run_bzr('arg1', 'arg2', 'arg3', retcode=1)
106
self.assertEqual(('arg1', 'arg2', 'arg3'), self.argv)
108
def test_encoding(self):
109
"""Test that run_bzr passes encoding to run_bzr_captured"""
110
self.run_bzr('foo', 'bar')
111
self.assertEqual(None, self.encoding)
112
self.assertEqual(('foo', 'bar'), self.argv)
114
self.run_bzr('foo', 'bar', encoding='baz')
115
self.assertEqual('baz', self.encoding)
116
self.assertEqual(('foo', 'bar'), self.argv)
118
def test_retcode(self):
119
"""Test that run_bzr passes retcode to run_bzr_captured"""
120
# Default is retcode == 0
121
self.run_bzr('foo', 'bar')
122
self.assertEqual(0, self.retcode)
123
self.assertEqual(('foo', 'bar'), self.argv)
125
self.run_bzr('foo', 'bar', retcode=1)
126
self.assertEqual(1, self.retcode)
127
self.assertEqual(('foo', 'bar'), self.argv)
129
self.run_bzr('foo', 'bar', retcode=None)
130
self.assertEqual(None, self.retcode)
131
self.assertEqual(('foo', 'bar'), self.argv)
133
self.run_bzr('foo', 'bar', retcode=3)
134
self.assertEqual(3, self.retcode)
135
self.assertEqual(('foo', 'bar'), self.argv)
92
137
def test_stdin(self):
93
138
# test that the stdin keyword to run_bzr is passed through to
97
142
# should invoke it.
98
143
self.run_bzr('foo', 'bar', stdin='gam')
99
144
self.assertEqual('gam', self.stdin)
145
self.assertEqual(('foo', 'bar'), self.argv)
100
147
self.run_bzr('foo', 'bar', stdin='zippy')
101
148
self.assertEqual('zippy', self.stdin)
149
self.assertEqual(('foo', 'bar'), self.argv)
151
def test_working_dir(self):
152
"""Test that run_bzr passes working_dir to run_bzr_captured"""
153
self.run_bzr('foo', 'bar')
154
self.assertEqual(None, self.working_dir)
155
self.assertEqual(('foo', 'bar'), self.argv)
157
self.run_bzr('foo', 'bar', working_dir='baz')
158
self.assertEqual('baz', self.working_dir)
159
self.assertEqual(('foo', 'bar'), self.argv)
104
162
class TestBenchmarkTests(TestCaseWithTransport):
163
222
self.assertEqual('bar\n', self.factory.stderr.getvalue())
164
223
self.assertIsInstance(self.factory, bzrlib.tests.blackbox.TestUIFactory)
225
def test_working_dir(self):
226
self.build_tree(['one/', 'two/'])
227
cwd = osutils.getcwd()
229
# Default is to work in the current directory
230
self.run_bzr_captured(['foo', 'bar'])
231
self.assertEqual(cwd, self.working_dir)
233
self.run_bzr_captured(['foo', 'bar'], working_dir=None)
234
self.assertEqual(cwd, self.working_dir)
236
# The function should be run in the alternative directory
237
# but afterwards the current working dir shouldn't be changed
238
self.run_bzr_captured(['foo', 'bar'], working_dir='one')
239
self.assertNotEqual(cwd, self.working_dir)
240
self.assertEndsWith(self.working_dir, 'one')
241
self.assertEqual(cwd, osutils.getcwd())
243
self.run_bzr_captured(['foo', 'bar'], working_dir='two')
244
self.assertNotEqual(cwd, self.working_dir)
245
self.assertEndsWith(self.working_dir, 'two')
246
self.assertEqual(cwd, osutils.getcwd())
249
class TestRunBzrSubprocess(TestCaseWithTransport):
166
251
def test_run_bzr_subprocess(self):
167
252
"""The run_bzr_helper_external comand behaves nicely."""
168
253
result = self.run_bzr_subprocess('--version')
244
329
self.assertEqual('it sure does!\n', out)
245
330
self.assertEqual('', err)
332
def test_run_bzr_subprocess_working_dir(self):
333
"""Test that we can specify the working dir for the child"""
334
cwd = osutils.getcwd()
336
self.make_branch_and_tree('.')
337
self.make_branch_and_tree('one')
338
self.make_branch_and_tree('two')
340
def get_root(**kwargs):
341
"""Spawn a process to get the 'root' of the tree.
343
You can pass in arbitrary new arguments. This just makes
344
sure that the returned path doesn't have trailing whitespace.
346
return self.run_bzr_subprocess('root', **kwargs)[0].rstrip()
348
self.assertEqual(cwd, get_root())
349
self.assertEqual(cwd, get_root(working_dir=None))
350
# Has our path changed?
351
self.assertEqual(cwd, osutils.getcwd())
353
dir1 = get_root(working_dir='one')
354
self.assertEndsWith(dir1, 'one')
355
self.assertEqual(cwd, osutils.getcwd())
357
dir2 = get_root(working_dir='two')
358
self.assertEndsWith(dir2, 'two')
359
self.assertEqual(cwd, osutils.getcwd())
362
class TestBzrSubprocess(TestCaseWithTransport):
247
364
def test_start_and_stop_bzr_subprocess(self):
248
365
"""We can start and perform other test actions while that process is
288
405
self.assertEqual('', result[0])
289
406
self.assertEqual('bzr: interrupted\n', result[1])
408
def test_start_and_stop_working_dir(self):
409
cwd = osutils.getcwd()
411
self.make_branch_and_tree('one')
413
process = self.start_bzr_subprocess(['root'], working_dir='one')
414
result = self.finish_bzr_subprocess(process)
415
self.assertEndsWith(result[0], 'one\n')
416
self.assertEqual('', result[1])
292
419
class TestRunBzrError(ExternalBase):