~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-07-18 13:38:13 UTC
  • Revision ID: mbp@sourcefrog.net-20050718133813-4343f0cde39537de
- refactor member names in Weave code

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
it's normally invoked.
27
27
"""
28
28
 
29
 
import sys
30
 
from bzrlib.selftest import InTempDir, BzrTestBase
 
29
# this code was previously in testbzr
 
30
 
 
31
from unittest import TestCase
 
32
from bzrlib.selftest import TestBase, InTempDir
 
33
 
 
34
 
31
35
 
32
36
class ExternalBase(InTempDir):
33
 
 
34
 
    def runbzr(self, args, retcode=0,backtick=False):
 
37
    def runbzr(self, args, retcode=0):
35
38
        try:
36
39
            import shutil
37
40
            from subprocess import call
41
44
 
42
45
        if isinstance(args, basestring):
43
46
            args = args.split()
44
 
 
45
 
        if backtick:
46
 
            return self.backtick(['python', self.BZRPATH,] + args,
47
 
                           retcode=retcode)
48
 
        else:
49
 
            return self.runcmd(['python', self.BZRPATH,] + args,
50
 
                           retcode=retcode)
51
 
 
52
 
class TestCommands(ExternalBase):
53
 
 
54
 
    def test_help_commands(self):
 
47
            
 
48
        return self.runcmd(['python', self.BZRPATH,] + args,
 
49
                           retcode=retcode)
 
50
 
 
51
 
 
52
 
 
53
class TestVersion(ExternalBase):
 
54
    def runTest(self):
 
55
        # output is intentionally passed through to stdout so that we
 
56
        # can see the version being tested
 
57
        self.runbzr(['version'])
 
58
 
 
59
 
 
60
 
 
61
class HelpCommands(ExternalBase):
 
62
    def runTest(self):
55
63
        self.runbzr('--help')
56
64
        self.runbzr('help')
57
65
        self.runbzr('help commands')
58
66
        self.runbzr('help help')
59
67
        self.runbzr('commit -h')
60
68
 
61
 
    def test_init_branch(self):
 
69
 
 
70
class InitBranch(ExternalBase):
 
71
    def runTest(self):
62
72
        import os
63
73
        self.runbzr(['init'])
64
74
 
65
 
    def test_whoami(self):
 
75
 
 
76
 
 
77
class UserIdentity(ExternalBase):
 
78
    def runTest(self):
66
79
        # this should always identify something, if only "john@localhost"
67
80
        self.runbzr("whoami")
68
81
        self.runbzr("whoami --email")
69
 
 
70
 
        self.assertEquals(self.runbzr("whoami --email",
71
 
                                      backtick=True).count('@'), 1)
72
 
        
73
 
    def test_whoami_branch(self):
74
 
        """branch specific user identity works."""
75
 
        self.runbzr('init')
76
 
        f = file('.bzr/email', 'wt')
77
 
        f.write('Branch Identity <branch@identi.ty>')
78
 
        f.close()
79
 
        whoami = self.runbzr("whoami",backtick=True)
80
 
        whoami_email = self.runbzr("whoami --email",backtick=True)
81
 
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
82
 
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
83
 
 
84
 
    def test_invalid_commands(self):
 
82
        self.assertEquals(self.backtick("bzr whoami --email").count('@'),
 
83
                          1)
 
84
 
 
85
 
 
86
class InvalidCommands(ExternalBase):
 
87
    def runTest(self):
85
88
        self.runbzr("pants", retcode=1)
86
89
        self.runbzr("--pants off", retcode=1)
87
90
        self.runbzr("diff --message foo", retcode=1)
88
91
 
89
 
    def test_empty_commit(self):
 
92
 
 
93
 
 
94
class EmptyCommit(ExternalBase):
 
95
    def runTest(self):
90
96
        self.runbzr("init")
91
97
        self.build_tree(['hello.txt'])
92
98
        self.runbzr("commit -m empty", retcode=1)
93
99
        self.runbzr("add hello.txt")
94
100
        self.runbzr("commit -m added")
95
101
 
96
 
    def test_ignore_patterns(self):
 
102
 
 
103
 
 
104
class IgnorePatterns(ExternalBase):
 
105
    def runTest(self):
97
106
        from bzrlib.branch import Branch
98
107
        
99
108
        b = Branch('.', init=True)
124
133
        self.runbzr('ignore garh')
125
134
        self.assertEquals(list(b.unknowns()), [])
126
135
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
127
 
 
128
 
    def test_revert(self):
129
 
        import os
130
 
        self.runbzr('init')
131
 
 
132
 
        file('hello', 'wt').write('foo')
133
 
        self.runbzr('add hello')
134
 
        self.runbzr('commit -m setup hello')
135
 
 
136
 
        file('goodbye', 'wt').write('baz')
137
 
        self.runbzr('add goodbye')
138
 
        self.runbzr('commit -m setup goodbye')
139
 
        
140
 
        file('hello', 'wt').write('bar')
141
 
        file('goodbye', 'wt').write('qux')
142
 
        self.runbzr('revert hello')
143
 
        self.check_file_contents('hello', 'foo')
144
 
        self.check_file_contents('goodbye', 'qux')
145
 
        self.runbzr('revert')
146
 
        self.check_file_contents('goodbye', 'baz')
147
 
 
148
 
        os.mkdir('revertdir')
149
 
        self.runbzr('add revertdir')
150
 
        self.runbzr('commit -m f')
151
 
        os.rmdir('revertdir')
152
 
        self.runbzr('revert')
153
 
 
154
 
    def skipped_test_mv_modes(self):
155
 
        """Test two modes of operation for mv"""
156
 
        from bzrlib.branch import Branch
157
 
        b = Branch('.', init=True)
158
 
        self.build_tree(['a', 'c', 'subdir/'])
159
 
        self.run_bzr('mv', 'a', 'b')
160
 
        self.run_bzr('mv', 'b', 'subdir')
161
 
        self.run_bzr('mv', 'subdir/b', 'a')
162
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
163
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
164
 
 
165
 
    def test_main_version(self):
166
 
        """Check output from version command and master option is reasonable"""
167
 
        # output is intentionally passed through to stdout so that we
168
 
        # can see the version being tested
169
 
        output = self.runbzr('version', backtick=1)
170
 
        self.log('bzr version output:')
171
 
        self.log(output)
172
 
        self.assert_(output.startswith('bzr (bazaar-ng) '))
173
 
        self.assertNotEqual(output.index('Canonical'), -1)
174
 
        # make sure --version is consistent
175
 
        tmp_output = self.runbzr('--version', backtick=1)
176
 
        self.log('bzr --version output:')
177
 
        self.log(tmp_output)
178
 
        self.assertEquals(output, tmp_output)
179
 
 
180
 
    def example_branch(test):
181
 
        test.runbzr('init')
182
 
        file('hello', 'wt').write('foo')
183
 
        test.runbzr('add hello')
184
 
        test.runbzr('commit -m setup hello')
185
 
        file('goodbye', 'wt').write('baz')
186
 
        test.runbzr('add goodbye')
187
 
        test.runbzr('commit -m setup goodbye')
188
 
 
189
 
    def test_revert(self):
190
 
        self.example_branch()
191
 
        file('hello', 'wt').write('bar')
192
 
        file('goodbye', 'wt').write('qux')
193
 
        self.runbzr('revert hello')
194
 
        self.check_file_contents('hello', 'foo')
195
 
        self.check_file_contents('goodbye', 'qux')
196
 
        self.runbzr('revert')
197
 
        self.check_file_contents('goodbye', 'baz')
198
 
 
199
 
    def test_merge(self):
200
 
        from bzrlib.branch import Branch
201
 
        from bzrlib.commands import run_bzr
202
 
        import os
203
 
        
204
 
        os.mkdir('a')
205
 
        os.chdir('a')
206
 
 
207
 
        self.example_branch()
208
 
        os.chdir('..')
209
 
        self.runbzr('branch a b')
210
 
        os.chdir('b')
211
 
        file('goodbye', 'wt').write('quux')
212
 
        self.runbzr(['commit',  '-m',  "more u's are always good"])
213
 
 
214
 
        os.chdir('../a')
215
 
        file('hello', 'wt').write('quuux')
216
 
        # We can't merge when there are in-tree changes
217
 
        self.runbzr('merge ../b', retcode=1)
218
 
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
219
 
        self.runbzr('merge ../b')
220
 
        self.check_file_contents('goodbye', 'quux')
221
 
        # Merging a branch pulls its revision into the tree
222
 
        a = Branch('.')
223
 
        b = Branch('../b')
224
 
        a.get_revision_xml(b.last_patch())
225
 
 
226
 
        self.log('pending merges: %s', a.pending_merges())
227
 
#        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
228
 
#        % (a.pending_merges(), b.last_patch())
 
136
        
 
137
 
 
138
 
229
139
 
230
140
class OldTests(ExternalBase):
231
 
    """old tests moved from ./testbzr."""
232
 
 
233
 
    def test_bzr(self):
 
141
    # old tests moved from ./testbzr
 
142
    def runTest(self):
234
143
        from os import chdir, mkdir
235
144
        from os.path import exists
236
145
        import os
398
307
 
399
308
        runbzr('info')
400
309
 
 
310
 
 
311
 
 
312
 
 
313
 
 
314
 
 
315
        chdir('..')
 
316
        chdir('..')
 
317
        progress('branch')
 
318
        assert os.path.exists('branch1')
 
319
        assert not os.path.exists('branch2')
 
320
        # Can't create a branch if it already exists
 
321
        runbzr('branch branch1', retcode=1)
 
322
        # Can't create a branch if its parent doesn't exist
 
323
        runbzr('branch /unlikely/to/exist', retcode=1)
 
324
        runbzr('branch branch1 branch2')
 
325
        assert exists('branch2')
 
326
        assert exists('branch2/sub1')
 
327
        assert exists('branch2/sub1/hello.txt')
 
328
        
 
329
        runbzr('branch --revision 0 branch1 branch3')
 
330
        assert not exists('branch3/sub1/hello.txt')
 
331
        runbzr('branch --revision 0..3 branch1 branch4', retcode=1)
 
332
 
 
333
        progress("pull")
 
334
        chdir('branch1')
 
335
        runbzr('pull', retcode=1)
 
336
        runbzr('pull ../branch2')
 
337
        chdir('.bzr')
 
338
        runbzr('pull')
 
339
        runbzr('commit --unchanged -m empty')
 
340
        runbzr('pull')
 
341
        chdir('../../branch2')
 
342
        runbzr('pull')
 
343
        runbzr('commit --unchanged -m empty')
 
344
        chdir('../branch1')
 
345
        runbzr('commit --unchanged -m empty')
 
346
        runbzr('pull', retcode=1)
 
347
        chdir ('..')
 
348
 
 
349
        progress('status after remove')
 
350
        mkdir('status-after-remove')
 
351
        # see mail from William Dodé, 2005-05-25
 
352
        # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
 
353
        #     * looking for changes...
 
354
        #     added a
 
355
        #     * commited r1
 
356
        #     $ bzr remove a
 
357
        #     $ bzr status
 
358
        #     bzr: local variable 'kind' referenced before assignment
 
359
        #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
 
360
        #     see ~/.bzr.log for debug information
 
361
        chdir('status-after-remove')
 
362
        runbzr('init')
 
363
        file('a', 'w').write('foo')
 
364
        runbzr('add a')
 
365
        runbzr(['commit', '-m', 'add a'])
 
366
        runbzr('remove a')
 
367
        runbzr('status')
 
368
 
 
369
        chdir('..')
 
370
 
 
371
 
 
372
 
 
373
        progress("recursive and non-recursive add")
 
374
        mkdir('no-recurse')
 
375
        chdir('no-recurse')
 
376
        runbzr('init')
 
377
        mkdir('foo')
 
378
        fp = os.path.join('foo', 'test.txt')
 
379
        f = file(fp, 'w')
 
380
        f.write('hello!\n')
 
381
        f.close()
 
382
        runbzr('add --no-recurse foo')
 
383
        runbzr('file-id foo')
 
384
        runbzr('file-id ' + fp, 1)      # not versioned yet
 
385
        runbzr('commit -m add-dir-only')
 
386
 
 
387
        self.runbzr('file-id ' + fp, 1)      # still not versioned 
 
388
 
 
389
        self.runbzr('add foo')
 
390
        self.runbzr('file-id ' + fp)
 
391
        self.runbzr('commit -m add-sub-file')
 
392
 
 
393
        chdir('..')
 
394
 
 
395
 
 
396
 
 
397
class RevertCommand(ExternalBase):
 
398
    def runTest(self):
 
399
        self.runbzr('init')
 
400
 
 
401
        file('hello', 'wt').write('foo')
 
402
        self.runbzr('add hello')
 
403
        self.runbzr('commit -m setup hello')
 
404
        
 
405
        file('hello', 'wt').write('bar')
 
406
        self.runbzr('revert hello')
 
407
        self.check_file_contents('hello', 'foo')
 
408