76
76
TestCaseWithMemoryTransport.TEST_ROOT = None
78
78
TestOptions.current_test = "test_transport_set_to_sftp"
79
stdout = self.run_bzr_captured(
79
stdout = self.run_bzr(
80
80
'selftest --transport=sftp test_transport_set_to_sftp')[0]
81
81
self.assertContainsRe(stdout, 'Ran 1 test')
82
82
self.assertEqual(old_transport, bzrlib.tests.default_transport)
84
84
TestOptions.current_test = "test_transport_set_to_memory"
85
stdout = self.run_bzr_captured(
85
stdout = self.run_bzr(
86
86
'selftest --transport=memory test_transport_set_to_memory')[0]
87
87
self.assertContainsRe(stdout, 'Ran 1 test')
88
88
self.assertEqual(old_transport, bzrlib.tests.default_transport)
97
97
def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
99
"""Override run_bzr_captured to test how it is invoked by run_bzr.
99
"""Override _run_bzr_core to test how it is invoked by run_bzr.
101
101
Attempts to run bzr from inside this class don't actually run it.
103
We test how run_bzr_captured actually invokes bzr in another location.
103
We test how run_bzr actually invokes bzr in another location.
104
104
Here we only need to test that it is run_bzr passes the right
105
parameters to run_bzr_captured.
105
parameters to run_bzr.
107
107
self.argv = list(argv)
108
108
self.retcode = retcode
121
121
self.assertEqual(['arg1', 'arg2', 'arg3'], self.argv)
123
123
def test_encoding(self):
124
"""Test that run_bzr passes encoding to run_bzr_captured"""
124
"""Test that run_bzr passes encoding to _run_bzr_core"""
125
125
self.run_bzr('foo bar')
126
126
self.assertEqual(None, self.encoding)
127
127
self.assertEqual(['foo', 'bar'], self.argv)
131
131
self.assertEqual(['foo', 'bar'], self.argv)
133
133
def test_retcode(self):
134
"""Test that run_bzr passes retcode to run_bzr_captured"""
134
"""Test that run_bzr passes retcode to _run_bzr_core"""
135
135
# Default is retcode == 0
136
136
self.run_bzr('foo bar')
137
137
self.assertEqual(0, self.retcode)
152
152
def test_stdin(self):
153
153
# test that the stdin keyword to run_bzr is passed through to
154
# run_bzr_captured as-is. We do this by overriding
155
# run_bzr_captured in this class, and then calling run_bzr,
156
# which is a convenience function for run_bzr_captured, so
154
# _run_bzr_core as-is. We do this by overriding
155
# _run_bzr_core in this class, and then calling run_bzr,
156
# which is a convenience function for _run_bzr_core, so
157
157
# should invoke it.
158
158
self.run_bzr('foo bar', stdin='gam')
159
159
self.assertEqual('gam', self.stdin)
164
164
self.assertEqual(['foo', 'bar'], self.argv)
166
166
def test_working_dir(self):
167
"""Test that run_bzr passes working_dir to run_bzr_captured"""
167
"""Test that run_bzr passes working_dir to _run_bzr_core"""
168
168
self.run_bzr('foo bar')
169
169
self.assertEqual(None, self.working_dir)
170
170
self.assertEqual(['foo', 'bar'], self.argv)
215
215
def test_stdin(self):
216
# test that the stdin keyword to run_bzr_captured is passed through to
216
# test that the stdin keyword to _run_bzr_core is passed through to
217
217
# apply_redirected as a StringIO. We do this by overriding
218
# apply_redirected in this class, and then calling run_bzr_captured,
218
# apply_redirected in this class, and then calling _run_bzr_core,
219
219
# which calls apply_redirected.
220
self.run_bzr_captured(['foo', 'bar'], stdin='gam')
220
self.run_bzr(['foo', 'bar'], stdin='gam')
221
221
self.assertEqual('gam', self.stdin.read())
222
222
self.assertTrue(self.stdin is self.factory_stdin)
223
self.run_bzr_captured(['foo', 'bar'], stdin='zippy')
223
self.run_bzr(['foo', 'bar'], stdin='zippy')
224
224
self.assertEqual('zippy', self.stdin.read())
225
225
self.assertTrue(self.stdin is self.factory_stdin)
227
227
def test_ui_factory(self):
228
# each invocation of self.run_bzr_captured should get its
228
# each invocation of self.run_bzr should get its
229
229
# own UI factory, which is an instance of TestUIFactory,
230
230
# with stdin, stdout and stderr attached to the stdin,
231
# stdout and stderr of the invoked run_bzr_captured
231
# stdout and stderr of the invoked run_bzr
232
232
current_factory = bzrlib.ui.ui_factory
233
self.run_bzr_captured(['foo'])
233
self.run_bzr(['foo'])
234
234
self.failIf(current_factory is self.factory)
235
235
self.assertNotEqual(sys.stdout, self.factory.stdout)
236
236
self.assertNotEqual(sys.stderr, self.factory.stderr)
243
243
cwd = osutils.getcwd()
245
245
# Default is to work in the current directory
246
self.run_bzr_captured(['foo', 'bar'])
246
self.run_bzr(['foo', 'bar'])
247
247
self.assertEqual(cwd, self.working_dir)
249
self.run_bzr_captured(['foo', 'bar'], working_dir=None)
249
self.run_bzr(['foo', 'bar'], working_dir=None)
250
250
self.assertEqual(cwd, self.working_dir)
252
252
# The function should be run in the alternative directory
253
253
# but afterwards the current working dir shouldn't be changed
254
self.run_bzr_captured(['foo', 'bar'], working_dir='one')
254
self.run_bzr(['foo', 'bar'], working_dir='one')
255
255
self.assertNotEqual(cwd, self.working_dir)
256
256
self.assertEndsWith(self.working_dir, 'one')
257
257
self.assertEqual(cwd, osutils.getcwd())
259
self.run_bzr_captured(['foo', 'bar'], working_dir='two')
259
self.run_bzr(['foo', 'bar'], working_dir='two')
260
260
self.assertNotEqual(cwd, self.working_dir)
261
261
self.assertEndsWith(self.working_dir, 'two')
262
262
self.assertEqual(cwd, osutils.getcwd())
491
491
'test9999.tmp','tests'],
494
out,err = self.run_bzr_captured(['selftest','--clean-output'],
494
out, err = self.run_bzr(['selftest','--clean-output'],
495
495
working_dir=root)
497
497
self.assertEquals(['delete directory: test0000.tmp',
541
541
def test_list_only(self):
542
542
# check that bzr selftest --list-only works correctly
543
out,err = self.run_bzr_captured(['selftest', 'selftest',
543
out,err = self.run_bzr(['selftest', 'selftest',
545
545
self.assertEndsWith(err, 'tests passed\n')
546
546
(header,body,footer) = self._parse_test_list(out.splitlines())
550
550
def test_list_only_filtered(self):
551
551
# check that a filtered --list-only works, both include and exclude
552
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only'])
552
out_all,err_all = self.run_bzr(['selftest', '--list-only'])
553
553
tests_all = self._parse_test_list(out_all.splitlines())[1]
554
out_incl,err_incl = self.run_bzr_captured(['selftest', '--list-only',
554
out_incl,err_incl = self.run_bzr(['selftest', '--list-only',
556
556
tests_incl = self._parse_test_list(out_incl.splitlines())[1]
557
557
self.assertSubset(tests_incl, tests_all)
558
out_excl,err_excl = self.run_bzr_captured(['selftest', '--list-only',
558
out_excl,err_excl = self.run_bzr(['selftest', '--list-only',
559
559
'--exclude', 'selftest'])
560
560
tests_excl = self._parse_test_list(out_excl.splitlines())[1]
561
561
self.assertSubset(tests_excl, tests_all)
568
568
def test_list_only_random(self):
569
569
# check that --randomize works correctly
570
out_all,err_all = self.run_bzr_captured(['selftest', '--list-only',
570
out_all,err_all = self.run_bzr(['selftest', '--list-only',
572
572
tests_all = self._parse_test_list(out_all.splitlines())[1]
573
573
# XXX: It looks like there are some orders for generating tests that
574
574
# fail as of 20070504 - maybe because of import order dependencies.
575
575
# So unfortunately this will rarely intermittently fail at the moment.
576
576
# -- mbp 20070504
577
out_rand,err_rand = self.run_bzr_captured(['selftest', '--list-only',
577
out_rand,err_rand = self.run_bzr(['selftest', '--list-only',
578
578
'selftest', '--randomize', 'now'])
579
579
(header_rand,tests_rand,dummy) = self._parse_test_list(
580
580
out_rand.splitlines(), 2)
584
584
seed_re = re.compile('Randomizing test order using seed (\w+)')
585
585
match_obj = seed_re.search(header_rand[-1])
586
586
seed = match_obj.group(1)
587
out_rand2,err_rand2 = self.run_bzr_captured(['selftest', '--list-only',
587
out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',
588
588
'selftest', '--randomize', seed])
589
589
(header_rand2,tests_rand2,dummy) = self._parse_test_list(
590
590
out_rand2.splitlines(), 2)