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

Clint Adams patch for shell completion hints

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
import sys
30
30
 
31
 
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
32
 
 
33
 
 
34
 
 
35
 
class ExternalBase(InTempDir):
36
 
    def runbzr(self, args, retcode=0):
37
 
        try:
38
 
            import shutil
39
 
            from subprocess import call
40
 
        except ImportError, e:
41
 
            _need_subprocess()
42
 
            raise
43
 
 
 
31
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
32
from bzrlib.branch import Branch
 
33
from bzrlib.commands import run_bzr
 
34
 
 
35
 
 
36
class ExternalBase(TestCaseInTempDir):
 
37
    def runbzr(self, args, retcode=0,backtick=False):
44
38
        if isinstance(args, basestring):
45
39
            args = args.split()
46
 
            
47
 
        return self.runcmd(['python', self.BZRPATH,] + args,
48
 
                           retcode=retcode)
49
 
 
50
 
 
51
 
 
52
 
class MvCommand(BzrTestBase):
53
 
    def runbzr(self):
54
 
        """Test two modes of operation for mv"""
55
 
        b = Branch('.', init=True)
56
 
        self.build_tree(['a', 'c', 'subdir/'])
57
 
        self.run_bzr('mv', 'a', 'b')
58
 
        self.run_bzr('mv', 'b', 'subdir')
59
 
        self.run_bzr('mv', 'subdir/b', 'a')
60
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
61
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
62
 
 
63
 
 
64
 
 
65
 
class TestVersion(BzrTestBase):
66
 
    """Check output from version command and master option is reasonable"""
67
 
    def runTest(self):
68
 
        # output is intentionally passed through to stdout so that we
69
 
        # can see the version being tested
70
 
        from cStringIO import StringIO
71
 
        save_out = sys.stdout
72
 
        try:
73
 
            sys.stdout = tmp_out = StringIO()
74
 
            
75
 
            self.run_bzr('version')
76
 
        finally:
77
 
            sys.stdout = save_out
78
 
 
79
 
        output = tmp_out.getvalue()
80
 
        self.log('bzr version output:')
81
 
        self.log(output)
82
 
        
83
 
        self.assert_(output.startswith('bzr (bazaar-ng) '))
84
 
        self.assertNotEqual(output.index('Canonical'), -1)
85
 
 
86
 
        # make sure --version is consistent
87
 
        try:
88
 
            sys.stdout = tmp_out = StringIO()
89
 
            
90
 
            self.run_bzr('--version')
91
 
        finally:
92
 
            sys.stdout = save_out
93
 
 
94
 
        self.log('bzr --version output:')
95
 
        self.log(tmp_out.getvalue())
96
 
 
97
 
        self.assertEquals(output, tmp_out.getvalue())
98
 
 
99
 
 
100
 
        
101
 
 
102
 
 
103
 
class HelpCommands(ExternalBase):
104
 
    def runTest(self):
 
40
 
 
41
        if backtick:
 
42
            return self.backtick(['python', self.BZRPATH,] + args,
 
43
                           retcode=retcode)
 
44
        else:
 
45
            return self.runcmd(['python', self.BZRPATH,] + args,
 
46
                           retcode=retcode)
 
47
 
 
48
 
 
49
class TestCommands(ExternalBase):
 
50
 
 
51
    def test_help_commands(self):
105
52
        self.runbzr('--help')
106
53
        self.runbzr('help')
107
54
        self.runbzr('help commands')
108
55
        self.runbzr('help help')
109
56
        self.runbzr('commit -h')
110
57
 
111
 
 
112
 
class InitBranch(ExternalBase):
113
 
    def runTest(self):
114
 
        import os
 
58
    def test_init_branch(self):
115
59
        self.runbzr(['init'])
116
60
 
117
 
 
118
 
 
119
 
class UserIdentity(ExternalBase):
120
 
    def runTest(self):
 
61
    def test_whoami(self):
121
62
        # this should always identify something, if only "john@localhost"
122
63
        self.runbzr("whoami")
123
64
        self.runbzr("whoami --email")
124
 
        self.assertEquals(self.backtick("bzr whoami --email").count('@'),
125
 
                          1)
126
 
 
127
 
 
128
 
class InvalidCommands(ExternalBase):
129
 
    def runTest(self):
 
65
 
 
66
        self.assertEquals(self.runbzr("whoami --email",
 
67
                                      backtick=True).count('@'), 1)
 
68
        
 
69
    def test_whoami_branch(self):
 
70
        """branch specific user identity works."""
 
71
        self.runbzr('init')
 
72
        f = file('.bzr/email', 'wt')
 
73
        f.write('Branch Identity <branch@identi.ty>')
 
74
        f.close()
 
75
        whoami = self.runbzr("whoami",backtick=True)
 
76
        whoami_email = self.runbzr("whoami --email",backtick=True)
 
77
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
 
78
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
 
79
 
 
80
    def test_invalid_commands(self):
130
81
        self.runbzr("pants", retcode=1)
131
82
        self.runbzr("--pants off", retcode=1)
132
83
        self.runbzr("diff --message foo", retcode=1)
133
84
 
134
 
 
135
 
 
136
 
class EmptyCommit(ExternalBase):
137
 
    def runTest(self):
 
85
    def test_empty_commit(self):
138
86
        self.runbzr("init")
139
87
        self.build_tree(['hello.txt'])
140
88
        self.runbzr("commit -m empty", retcode=1)
141
89
        self.runbzr("add hello.txt")
142
90
        self.runbzr("commit -m added")
143
91
 
144
 
 
145
 
 
146
 
class IgnorePatterns(ExternalBase):
147
 
    def runTest(self):
 
92
    def test_ignore_patterns(self):
148
93
        from bzrlib.branch import Branch
149
94
        
150
95
        b = Branch('.', init=True)
175
120
        self.runbzr('ignore garh')
176
121
        self.assertEquals(list(b.unknowns()), [])
177
122
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
178
 
        
179
 
 
 
123
 
 
124
    def test_revert(self):
 
125
        import os
 
126
        self.runbzr('init')
 
127
 
 
128
        file('hello', 'wt').write('foo')
 
129
        self.runbzr('add hello')
 
130
        self.runbzr('commit -m setup hello')
 
131
 
 
132
        file('goodbye', 'wt').write('baz')
 
133
        self.runbzr('add goodbye')
 
134
        self.runbzr('commit -m setup goodbye')
 
135
        
 
136
        file('hello', 'wt').write('bar')
 
137
        file('goodbye', 'wt').write('qux')
 
138
        self.runbzr('revert hello')
 
139
        self.check_file_contents('hello', 'foo')
 
140
        self.check_file_contents('goodbye', 'qux')
 
141
        self.runbzr('revert')
 
142
        self.check_file_contents('goodbye', 'baz')
 
143
 
 
144
        os.mkdir('revertdir')
 
145
        self.runbzr('add revertdir')
 
146
        self.runbzr('commit -m f')
 
147
        os.rmdir('revertdir')
 
148
        self.runbzr('revert')
 
149
 
 
150
    def test_mv_modes(self):
 
151
        """Test two modes of operation for mv"""
 
152
        from bzrlib.branch import Branch
 
153
        b = Branch('.', init=True)
 
154
        self.build_tree(['a', 'c', 'subdir/'])
 
155
        self.run_bzr('add', self.test_dir)
 
156
        self.run_bzr('mv', 'a', 'b')
 
157
        self.run_bzr('mv', 'b', 'subdir')
 
158
        self.run_bzr('mv', 'subdir/b', 'a')
 
159
        self.run_bzr('mv', 'a', 'c', 'subdir')
 
160
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
161
 
 
162
 
 
163
    def test_main_version(self):
 
164
        """Check output from version command and master option is reasonable"""
 
165
        # output is intentionally passed through to stdout so that we
 
166
        # can see the version being tested
 
167
        output = self.runbzr('version', backtick=1)
 
168
        self.log('bzr version output:')
 
169
        self.log(output)
 
170
        self.assert_(output.startswith('bzr (bazaar-ng) '))
 
171
        self.assertNotEqual(output.index('Canonical'), -1)
 
172
        # make sure --version is consistent
 
173
        tmp_output = self.runbzr('--version', backtick=1)
 
174
        self.log('bzr --version output:')
 
175
        self.log(tmp_output)
 
176
        self.assertEquals(output, tmp_output)
 
177
 
 
178
    def example_branch(test):
 
179
        test.runbzr('init')
 
180
        file('hello', 'wt').write('foo')
 
181
        test.runbzr('add hello')
 
182
        test.runbzr('commit -m setup hello')
 
183
        file('goodbye', 'wt').write('baz')
 
184
        test.runbzr('add goodbye')
 
185
        test.runbzr('commit -m setup goodbye')
 
186
 
 
187
    def test_revert(self):
 
188
        self.example_branch()
 
189
        file('hello', 'wt').write('bar')
 
190
        file('goodbye', 'wt').write('qux')
 
191
        self.runbzr('revert hello')
 
192
        self.check_file_contents('hello', 'foo')
 
193
        self.check_file_contents('goodbye', 'qux')
 
194
        self.runbzr('revert')
 
195
        self.check_file_contents('goodbye', 'baz')
 
196
 
 
197
    def test_merge(self):
 
198
        from bzrlib.branch import Branch
 
199
        import os
 
200
        
 
201
        os.mkdir('a')
 
202
        os.chdir('a')
 
203
 
 
204
        self.example_branch()
 
205
        os.chdir('..')
 
206
        self.runbzr('branch a b')
 
207
        os.chdir('b')
 
208
        file('goodbye', 'wt').write('quux')
 
209
        self.runbzr(['commit',  '-m',  "more u's are always good"])
 
210
 
 
211
        os.chdir('../a')
 
212
        file('hello', 'wt').write('quuux')
 
213
        # We can't merge when there are in-tree changes
 
214
        self.runbzr('merge ../b', retcode=1)
 
215
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
 
216
        self.runbzr('merge ../b')
 
217
        self.check_file_contents('goodbye', 'quux')
 
218
        # Merging a branch pulls its revision into the tree
 
219
        a = Branch('.')
 
220
        b = Branch('../b')
 
221
        a.get_revision_xml(b.last_patch())
 
222
 
 
223
        self.log('pending merges: %s', a.pending_merges())
 
224
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
 
225
        #        % (a.pending_merges(), b.last_patch())
 
226
 
 
227
 
 
228
    def test_add_reports(self):
 
229
        """add command prints the names of added files."""
 
230
        b = Branch('.', init=True)
 
231
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
232
 
 
233
        from cStringIO import StringIO
 
234
        out = StringIO()
 
235
 
 
236
        ret = self.apply_redirected(None, out, None,
 
237
                                    run_bzr,
 
238
                                    ['add'])
 
239
        self.assertEquals(ret, 0)
 
240
 
 
241
        # the ordering is not defined at the moment
 
242
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
 
243
        self.assertEquals(['added dir',
 
244
                           'added dir/sub.txt',
 
245
                           'added top.txt',],
 
246
                          results)
180
247
 
181
248
 
182
249
class OldTests(ExternalBase):
183
 
    # old tests moved from ./testbzr
184
 
    def runTest(self):
 
250
    """old tests moved from ./testbzr."""
 
251
 
 
252
    def test_bzr(self):
185
253
        from os import chdir, mkdir
186
254
        from os.path import exists
187
255
        import os
349
417
 
350
418
        runbzr('info')
351
419
 
352
 
 
353
 
 
354
 
 
355
 
 
356
 
 
357
 
class RevertCommand(ExternalBase):
358
 
    def runTest(self):
359
 
        self.runbzr('init')
360
 
 
361
 
        file('hello', 'wt').write('foo')
362
 
        self.runbzr('add hello')
363
 
        self.runbzr('commit -m setup hello')
364
 
        
365
 
        file('hello', 'wt').write('bar')
366
 
        self.runbzr('revert hello')
367
 
        self.check_file_contents('hello', 'foo')
368