/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/blackbox/test_selftest.py

  • Committer: John Arbash Meinel
  • Date: 2007-07-11 23:45:20 UTC
  • mfrom: (2601 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070711234520-do3h7zw8skbathpz
[merge] bzr.dev 2601

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
34
34
                          TestUIFactory,
35
35
                          TestSkipped,
36
36
                          )
 
37
from bzrlib.symbol_versioning import (
 
38
    zero_eighteen,
 
39
    )
37
40
from bzrlib.tests.blackbox import ExternalBase
38
41
 
39
42
 
73
76
        TestCaseWithMemoryTransport.TEST_ROOT = None
74
77
        try:
75
78
            TestOptions.current_test = "test_transport_set_to_sftp"
76
 
            stdout = self.capture('selftest --transport=sftp test_transport_set_to_sftp')
77
 
            
 
79
            stdout = self.run_bzr(
 
80
                'selftest --transport=sftp test_transport_set_to_sftp')[0]
78
81
            self.assertContainsRe(stdout, 'Ran 1 test')
79
82
            self.assertEqual(old_transport, bzrlib.tests.default_transport)
80
83
 
81
84
            TestOptions.current_test = "test_transport_set_to_memory"
82
 
            stdout = self.capture('selftest --transport=memory test_transport_set_to_memory')
 
85
            stdout = self.run_bzr(
 
86
                'selftest --transport=memory test_transport_set_to_memory')[0]
83
87
            self.assertContainsRe(stdout, 'Ran 1 test')
84
88
            self.assertEqual(old_transport, bzrlib.tests.default_transport)
85
89
        finally:
90
94
 
91
95
class TestRunBzr(ExternalBase):
92
96
 
93
 
    def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None,
 
97
    def _run_bzr_core(self, argv, retcode=0, encoding=None, stdin=None,
94
98
                         working_dir=None):
95
 
        """Override run_bzr_captured to test how it is invoked by run_bzr.
96
 
 
97
 
        We test how run_bzr_captured actually invokes bzr in another location.
 
99
        """Override _run_bzr_core to test how it is invoked by run_bzr.
 
100
 
 
101
        Attempts to run bzr from inside this class don't actually run it.
 
102
 
 
103
        We test how run_bzr actually invokes bzr in another location.
98
104
        Here we only need to test that it is run_bzr passes the right
99
 
        parameters to run_bzr_captured.
 
105
        parameters to run_bzr.
100
106
        """
101
 
        self.argv = argv
 
107
        self.argv = list(argv)
102
108
        self.retcode = retcode
103
109
        self.encoding = encoding
104
110
        self.stdin = stdin
106
112
        return '', ''
107
113
 
108
114
    def test_args(self):
109
 
        """Test that run_bzr passes args correctly to run_bzr_captured"""
110
 
        self.run_bzr('arg1', 'arg2', 'arg3', retcode=1)
111
 
        self.assertEqual(('arg1', 'arg2', 'arg3'), self.argv)
 
115
        """Test that run_bzr passes args correctly to _run_bzr_core"""
 
116
        self.callDeprecated(
 
117
                ['passing varargs to run_bzr was deprecated in version 0.18.'],
 
118
                self.run_bzr,
 
119
                'arg1', 'arg2', 'arg3', retcode=1)
 
120
        self.assertEqual(['arg1', 'arg2', 'arg3'], self.argv)
112
121
 
113
122
    def test_encoding(self):
114
 
        """Test that run_bzr passes encoding to run_bzr_captured"""
115
 
        self.run_bzr('foo', 'bar')
 
123
        """Test that run_bzr passes encoding to _run_bzr_core"""
 
124
        self.run_bzr('foo bar')
116
125
        self.assertEqual(None, self.encoding)
117
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
126
        self.assertEqual(['foo', 'bar'], self.argv)
118
127
 
119
 
        self.run_bzr('foo', 'bar', encoding='baz')
 
128
        self.run_bzr('foo bar', encoding='baz')
120
129
        self.assertEqual('baz', self.encoding)
121
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
130
        self.assertEqual(['foo', 'bar'], self.argv)
122
131
 
123
132
    def test_retcode(self):
124
 
        """Test that run_bzr passes retcode to run_bzr_captured"""
 
133
        """Test that run_bzr passes retcode to _run_bzr_core"""
125
134
        # Default is retcode == 0
126
 
        self.run_bzr('foo', 'bar')
 
135
        self.run_bzr('foo bar')
127
136
        self.assertEqual(0, self.retcode)
128
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
137
        self.assertEqual(['foo', 'bar'], self.argv)
129
138
 
130
 
        self.run_bzr('foo', 'bar', retcode=1)
 
139
        self.run_bzr('foo bar', retcode=1)
131
140
        self.assertEqual(1, self.retcode)
132
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
141
        self.assertEqual(['foo', 'bar'], self.argv)
133
142
 
134
 
        self.run_bzr('foo', 'bar', retcode=None)
 
143
        self.run_bzr('foo bar', retcode=None)
135
144
        self.assertEqual(None, self.retcode)
136
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
145
        self.assertEqual(['foo', 'bar'], self.argv)
137
146
 
138
 
        self.run_bzr('foo', 'bar', retcode=3)
 
147
        self.run_bzr(['foo', 'bar'], retcode=3)
139
148
        self.assertEqual(3, self.retcode)
140
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
149
        self.assertEqual(['foo', 'bar'], self.argv)
141
150
 
142
151
    def test_stdin(self):
143
152
        # test that the stdin keyword to run_bzr is passed through to
144
 
        # run_bzr_captured as-is. We do this by overriding
145
 
        # run_bzr_captured in this class, and then calling run_bzr,
146
 
        # which is a convenience function for run_bzr_captured, so 
 
153
        # _run_bzr_core as-is. We do this by overriding
 
154
        # _run_bzr_core in this class, and then calling run_bzr,
 
155
        # which is a convenience function for _run_bzr_core, so 
147
156
        # should invoke it.
148
 
        self.run_bzr('foo', 'bar', stdin='gam')
 
157
        self.run_bzr('foo bar', stdin='gam')
149
158
        self.assertEqual('gam', self.stdin)
150
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
159
        self.assertEqual(['foo', 'bar'], self.argv)
151
160
 
152
 
        self.run_bzr('foo', 'bar', stdin='zippy')
 
161
        self.run_bzr('foo bar', stdin='zippy')
153
162
        self.assertEqual('zippy', self.stdin)
154
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
163
        self.assertEqual(['foo', 'bar'], self.argv)
155
164
 
156
165
    def test_working_dir(self):
157
 
        """Test that run_bzr passes working_dir to run_bzr_captured"""
158
 
        self.run_bzr('foo', 'bar')
 
166
        """Test that run_bzr passes working_dir to _run_bzr_core"""
 
167
        self.run_bzr('foo bar')
159
168
        self.assertEqual(None, self.working_dir)
160
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
169
        self.assertEqual(['foo', 'bar'], self.argv)
161
170
 
162
 
        self.run_bzr('foo', 'bar', working_dir='baz')
 
171
        self.run_bzr('foo bar', working_dir='baz')
163
172
        self.assertEqual('baz', self.working_dir)
164
 
        self.assertEqual(('foo', 'bar'), self.argv)
 
173
        self.assertEqual(['foo', 'bar'], self.argv)
165
174
 
166
175
 
167
176
class TestBenchmarkTests(TestCaseWithTransport):
173
182
        old_root = TestCaseWithMemoryTransport.TEST_ROOT
174
183
        try:
175
184
            TestCaseWithMemoryTransport.TEST_ROOT = None
176
 
            out, err = self.run_bzr('selftest', '--benchmark', 'workingtree_implementations')
 
185
            out, err = self.run_bzr('selftest --benchmark'
 
186
                                    ' workingtree_implementations')
177
187
        finally:
178
188
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
179
189
        self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')
202
212
        return 0
203
213
 
204
214
    def test_stdin(self):
205
 
        # test that the stdin keyword to run_bzr_captured is passed through to
 
215
        # test that the stdin keyword to _run_bzr_core is passed through to
206
216
        # apply_redirected as a StringIO. We do this by overriding
207
 
        # apply_redirected in this class, and then calling run_bzr_captured,
 
217
        # apply_redirected in this class, and then calling _run_bzr_core,
208
218
        # which calls apply_redirected. 
209
 
        self.run_bzr_captured(['foo', 'bar'], stdin='gam')
 
219
        self.run_bzr(['foo', 'bar'], stdin='gam')
210
220
        self.assertEqual('gam', self.stdin.read())
211
221
        self.assertTrue(self.stdin is self.factory_stdin)
212
 
        self.run_bzr_captured(['foo', 'bar'], stdin='zippy')
 
222
        self.run_bzr(['foo', 'bar'], stdin='zippy')
213
223
        self.assertEqual('zippy', self.stdin.read())
214
224
        self.assertTrue(self.stdin is self.factory_stdin)
215
225
 
216
226
    def test_ui_factory(self):
217
 
        # each invocation of self.run_bzr_captured should get its
 
227
        # each invocation of self.run_bzr should get its
218
228
        # own UI factory, which is an instance of TestUIFactory,
219
229
        # with stdin, stdout and stderr attached to the stdin,
220
 
        # stdout and stderr of the invoked run_bzr_captured
 
230
        # stdout and stderr of the invoked run_bzr
221
231
        current_factory = bzrlib.ui.ui_factory
222
 
        self.run_bzr_captured(['foo'])
 
232
        self.run_bzr(['foo'])
223
233
        self.failIf(current_factory is self.factory)
224
234
        self.assertNotEqual(sys.stdout, self.factory.stdout)
225
235
        self.assertNotEqual(sys.stderr, self.factory.stderr)
232
242
        cwd = osutils.getcwd()
233
243
 
234
244
        # Default is to work in the current directory
235
 
        self.run_bzr_captured(['foo', 'bar'])
 
245
        self.run_bzr(['foo', 'bar'])
236
246
        self.assertEqual(cwd, self.working_dir)
237
247
 
238
 
        self.run_bzr_captured(['foo', 'bar'], working_dir=None)
 
248
        self.run_bzr(['foo', 'bar'], working_dir=None)
239
249
        self.assertEqual(cwd, self.working_dir)
240
250
 
241
251
        # The function should be run in the alternative directory
242
252
        # but afterwards the current working dir shouldn't be changed
243
 
        self.run_bzr_captured(['foo', 'bar'], working_dir='one')
 
253
        self.run_bzr(['foo', 'bar'], working_dir='one')
244
254
        self.assertNotEqual(cwd, self.working_dir)
245
255
        self.assertEndsWith(self.working_dir, 'one')
246
256
        self.assertEqual(cwd, osutils.getcwd())
247
257
 
248
 
        self.run_bzr_captured(['foo', 'bar'], working_dir='two')
 
258
        self.run_bzr(['foo', 'bar'], working_dir='two')
249
259
        self.assertNotEqual(cwd, self.working_dir)
250
260
        self.assertEndsWith(self.working_dir, 'two')
251
261
        self.assertEqual(cwd, osutils.getcwd())
423
433
        """
424
434
        process = self.start_bzr_subprocess(['--versionn'])
425
435
        self.assertRaises(self.failureException, self.finish_bzr_subprocess,
426
 
                          process, retcode=0)
 
436
                          process)
427
437
        
428
438
    def test_start_and_stop_bzr_subprocess_send_signal(self):
429
439
        """finish_bzr_subprocess raises self.failureException if the retcode is
451
461
class TestRunBzrError(ExternalBase):
452
462
 
453
463
    def test_run_bzr_error(self):
454
 
        out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
 
464
        # retcode=0 is specially needed here because run_bzr_error expects
 
465
        # an error (oddly enough) but we want to test the case of not
 
466
        # actually getting one
 
467
        out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=0)
455
468
        self.assertEqual(out, 'It sure does!\n')
456
 
 
457
 
        out, err = self.run_bzr_error(["bzr: ERROR: foobarbaz is not versioned"],
458
 
                                      'file-id', 'foobarbaz')
 
469
        # now test actually getting an error
 
470
        out, err = self.run_bzr_error(
 
471
                ["bzr: ERROR: foobarbaz is not versioned"],
 
472
                ['file-id', 'foobarbaz'])
459
473
 
460
474
 
461
475
class TestSelftestCleanOutput(TestCaseInTempDir):
480
494
                           'test9999.tmp','tests'],
481
495
                           before)
482
496
 
483
 
        out,err = self.run_bzr_captured(['selftest','--clean-output'],
484
 
                                        working_dir=root)
 
497
        out, err = self.run_bzr('selftest --clean-output',
 
498
                                working_dir=root)
485
499
 
486
500
        self.assertEquals(['delete directory: test0000.tmp',
487
501
                          'delete directory: test0001.tmp'],
529
543
 
530
544
    def test_list_only(self):
531
545
        # check that bzr selftest --list-only works correctly
532
 
        out,err = self.run_bzr_captured(['selftest', 'selftest',
533
 
            '--list-only'])
 
546
        out,err = self.run_bzr('selftest selftest --list-only')
534
547
        self.assertEndsWith(err, 'tests passed\n')
535
548
        (header,body,footer) = self._parse_test_list(out.splitlines())
536
549
        num_tests = len(body)
538
551
 
539
552
    def test_list_only_filtered(self):
540
553
        # check that a filtered --list-only works, both include and exclude
541
 
        out_all,err_all = self.run_bzr_captured(['selftest', '--list-only'])
 
554
        out_all,err_all = self.run_bzr('selftest --list-only')
542
555
        tests_all = self._parse_test_list(out_all.splitlines())[1]
543
 
        out_incl,err_incl = self.run_bzr_captured(['selftest', '--list-only',
544
 
          'selftest'])
 
556
        out_incl,err_incl = self.run_bzr('selftest --list-only selftest')
545
557
        tests_incl = self._parse_test_list(out_incl.splitlines())[1]
546
558
        self.assertSubset(tests_incl, tests_all)
547
 
        out_excl,err_excl = self.run_bzr_captured(['selftest', '--list-only',
548
 
          '--exclude', 'selftest'])
 
559
        out_excl,err_excl = self.run_bzr(['selftest', '--list-only',
 
560
                                          '--exclude', 'selftest'])
549
561
        tests_excl = self._parse_test_list(out_excl.splitlines())[1]
550
562
        self.assertSubset(tests_excl, tests_all)
551
563
        set_incl = set(tests_incl)
556
568
 
557
569
    def test_list_only_random(self):
558
570
        # check that --randomize works correctly
559
 
        out_all,err_all = self.run_bzr_captured(['selftest', '--list-only',
560
 
            'selftest'])
 
571
        out_all,err_all = self.run_bzr('selftest --list-only selftest')
561
572
        tests_all = self._parse_test_list(out_all.splitlines())[1]
562
 
        out_rand,err_rand = self.run_bzr_captured(['selftest', '--list-only',
563
 
            'selftest', '--randomize', 'now'])
 
573
        # XXX: It looks like there are some orders for generating tests that
 
574
        # fail as of 20070504 - maybe because of import order dependencies.
 
575
        # So unfortunately this will rarely intermittently fail at the moment.
 
576
        # -- mbp 20070504
 
577
        out_rand,err_rand = self.run_bzr(['selftest', '--list-only',
 
578
                                          'selftest', '--randomize', 'now'])
564
579
        (header_rand,tests_rand,dummy) = self._parse_test_list(
565
580
            out_rand.splitlines(), 2)
566
581
        self.assertNotEqual(tests_all, tests_rand)
569
584
        seed_re = re.compile('Randomizing test order using seed (\w+)')
570
585
        match_obj = seed_re.search(header_rand[-1])
571
586
        seed = match_obj.group(1)
572
 
        out_rand2,err_rand2 = self.run_bzr_captured(['selftest', '--list-only',
573
 
            'selftest', '--randomize', seed])
 
587
        out_rand2,err_rand2 = self.run_bzr(['selftest', '--list-only',
 
588
                                            'selftest', '--randomize', seed])
574
589
        (header_rand2,tests_rand2,dummy) = self._parse_test_list(
575
590
            out_rand2.splitlines(), 2)
576
591
        self.assertEqual(tests_rand, tests_rand2)