/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

  • Committer: Martin Pool
  • Date: 2005-07-11 06:41:00 UTC
  • mfrom: (unknown (missing))
  • Revision ID: mbp@sourcefrog.net-20050711064100-c2eb947e0212f487
- patch from john to search for matching commits

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
 
 
31
 
from bzrlib.selftest import TestBase, InTempDir, BzrTestBase
32
 
 
33
 
 
34
 
 
35
 
class ExternalBase(InTempDir):
36
 
    def runbzr(self, args, retcode=0):
 
29
# this code was previously in testbzr
 
30
 
 
31
from unittest import TestCase
 
32
from bzrlib.selftest import TestBase, InTempDir
 
33
 
 
34
 
 
35
 
 
36
class ExternalBase(TestBase):
 
37
    def runbzr(self, args):
37
38
        try:
38
39
            import shutil
39
40
            from subprocess import call
44
45
        if isinstance(args, basestring):
45
46
            args = args.split()
46
47
            
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"""
 
48
        return self.runcmd(['python', self.BZRPATH,] + args)
 
49
 
 
50
 
 
51
 
 
52
class TestVersion(TestBase):
67
53
    def runTest(self):
68
54
        # output is intentionally passed through to stdout so that we
69
55
        # 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):
 
56
        self.runbzr(['version'])
 
57
 
 
58
 
 
59
 
 
60
class HelpCommands(TestBase):
104
61
    def runTest(self):
105
62
        self.runbzr('--help')
106
63
        self.runbzr('help')
109
66
        self.runbzr('commit -h')
110
67
 
111
68
 
112
 
class InitBranch(ExternalBase):
 
69
class InitBranch(InTempDir):
113
70
    def runTest(self):
114
71
        import os
115
72
        self.runbzr(['init'])
116
73
 
117
74
 
118
75
 
119
 
class UserIdentity(ExternalBase):
 
76
class UserIdentity(InTempDir):
120
77
    def runTest(self):
121
78
        # this should always identify something, if only "john@localhost"
122
79
        self.runbzr("whoami")
125
82
                          1)
126
83
 
127
84
 
128
 
class InvalidCommands(ExternalBase):
 
85
class InvalidCommands(InTempDir):
129
86
    def runTest(self):
130
87
        self.runbzr("pants", retcode=1)
131
88
        self.runbzr("--pants off", retcode=1)
133
90
 
134
91
 
135
92
 
136
 
class EmptyCommit(ExternalBase):
 
93
class EmptyCommit(InTempDir):
137
94
    def runTest(self):
138
95
        self.runbzr("init")
139
96
        self.build_tree(['hello.txt'])
143
100
 
144
101
 
145
102
 
146
 
class IgnorePatterns(ExternalBase):
147
 
    def runTest(self):
148
 
        from bzrlib.branch import Branch
149
 
        
150
 
        b = Branch('.', init=True)
151
 
        self.assertEquals(list(b.unknowns()), [])
152
 
 
153
 
        file('foo.tmp', 'wt').write('tmp files are ignored')
154
 
        self.assertEquals(list(b.unknowns()), [])
155
 
        assert self.backtick('bzr unknowns') == ''
156
 
 
157
 
        file('foo.c', 'wt').write('int main() {}')
158
 
        self.assertEquals(list(b.unknowns()), ['foo.c'])
159
 
        assert self.backtick('bzr unknowns') == 'foo.c\n'
160
 
 
161
 
        self.runbzr(['add', 'foo.c'])
162
 
        assert self.backtick('bzr unknowns') == ''
163
 
 
164
 
        # 'ignore' works when creating the .bzignore file
165
 
        file('foo.blah', 'wt').write('blah')
166
 
        self.assertEquals(list(b.unknowns()), ['foo.blah'])
167
 
        self.runbzr('ignore *.blah')
168
 
        self.assertEquals(list(b.unknowns()), [])
169
 
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
170
 
 
171
 
        # 'ignore' works when then .bzrignore file already exists
172
 
        file('garh', 'wt').write('garh')
173
 
        self.assertEquals(list(b.unknowns()), ['garh'])
174
 
        assert self.backtick('bzr unknowns') == 'garh\n'
175
 
        self.runbzr('ignore garh')
176
 
        self.assertEquals(list(b.unknowns()), [])
177
 
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
178
 
        
179
 
 
180
 
 
181
 
 
182
 
class OldTests(ExternalBase):
 
103
class OldTests(InTempDir):
183
104
    # old tests moved from ./testbzr
184
105
    def runTest(self):
185
106
        from os import chdir, mkdir
186
107
        from os.path import exists
187
108
        import os
188
109
 
189
 
        runbzr = self.runbzr
 
110
        runcmd = self.runcmd
190
111
        backtick = self.backtick
191
112
        progress = self.log
192
113
 
193
114
        progress("basic branch creation")
194
 
        mkdir('branch1')
 
115
        runcmd(['mkdir', 'branch1'])
195
116
        chdir('branch1')
196
117
        runbzr('init')
197
118
 
266
187
        assert backtick("bzr revno") == '0\n'
267
188
 
268
189
        progress("add first revision")
269
 
        runbzr(['commit', '-m', 'add first revision'])
 
190
        runcmd(["bzr", "commit", "-m", 'add first revision'])
270
191
 
271
192
        progress("more complex renames")
272
193
        os.mkdir("sub1")
327
248
 
328
249
        runbzr('log')
329
250
        runbzr('log -v')
330
 
        runbzr('log -v --forward')
331
 
        runbzr('log -m', retcode=1)
332
 
        log_out = backtick('bzr log -m commit')
333
 
        assert "this is my new commit" in log_out
334
 
        assert "rename nested" not in log_out
335
 
        assert 'revision-id' not in log_out
336
 
        assert 'revision-id' in backtick('bzr log --show-ids -m commit')
 
251
 
337
252
 
338
253
 
339
254
        progress("file with spaces in name")
354
269
 
355
270
 
356
271
 
357
 
class RevertCommand(ExternalBase):
 
272
        chdir('..')
 
273
        chdir('..')
 
274
        progress('branch')
 
275
        # Can't create a branch if it already exists
 
276
        runbzr('branch branch1', retcode=1)
 
277
        # Can't create a branch if its parent doesn't exist
 
278
        runbzr('branch /unlikely/to/exist', retcode=1)
 
279
        runbzr('branch branch1 branch2')
 
280
 
 
281
        progress("pull")
 
282
        chdir('branch1')
 
283
        runbzr('pull', retcode=1)
 
284
        runbzr('pull ../branch2')
 
285
        chdir('.bzr')
 
286
        runbzr('pull')
 
287
        runbzr('commit --unchanged -m empty')
 
288
        runbzr('pull')
 
289
        chdir('../../branch2')
 
290
        runbzr('pull')
 
291
        runbzr('commit --unchanged -m empty')
 
292
        chdir('../branch1')
 
293
        runbzr('commit --unchanged -m empty')
 
294
        runbzr('pull', retcode=1)
 
295
        chdir ('..')
 
296
 
 
297
        progress('status after remove')
 
298
        mkdir('status-after-remove')
 
299
        # see mail from William Dodé, 2005-05-25
 
300
        # $ bzr init; touch a; bzr add a; bzr commit -m "add a"
 
301
        #     * looking for changes...
 
302
        #     added a
 
303
        #     * commited r1
 
304
        #     $ bzr remove a
 
305
        #     $ bzr status
 
306
        #     bzr: local variable 'kind' referenced before assignment
 
307
        #     at /vrac/python/bazaar-ng/bzrlib/diff.py:286 in compare_trees()
 
308
        #     see ~/.bzr.log for debug information
 
309
        chdir('status-after-remove')
 
310
        runbzr('init')
 
311
        file('a', 'w').write('foo')
 
312
        runbzr('add a')
 
313
        runbzr(['commit', '-m', 'add a'])
 
314
        runbzr('remove a')
 
315
        runbzr('status')
 
316
 
 
317
        chdir('..')
 
318
 
 
319
        progress('ignore patterns')
 
320
        mkdir('ignorebranch')
 
321
        chdir('ignorebranch')
 
322
        runbzr('init')
 
323
        assert backtick('bzr unknowns') == ''
 
324
 
 
325
        file('foo.tmp', 'wt').write('tmp files are ignored')
 
326
        assert backtick('bzr unknowns') == ''
 
327
 
 
328
        file('foo.c', 'wt').write('int main() {}')
 
329
        assert backtick('bzr unknowns') == 'foo.c\n'
 
330
        runbzr('add foo.c')
 
331
        assert backtick('bzr unknowns') == ''
 
332
 
 
333
        # 'ignore' works when creating the .bzignore file
 
334
        file('foo.blah', 'wt').write('blah')
 
335
        assert backtick('bzr unknowns') == 'foo.blah\n'
 
336
        runbzr('ignore *.blah')
 
337
        assert backtick('bzr unknowns') == ''
 
338
        assert file('.bzrignore', 'rb').read() == '*.blah\n'
 
339
 
 
340
        # 'ignore' works when then .bzrignore file already exists
 
341
        file('garh', 'wt').write('garh')
 
342
        assert backtick('bzr unknowns') == 'garh\n'
 
343
        runbzr('ignore garh')
 
344
        assert backtick('bzr unknowns') == ''
 
345
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
 
346
 
 
347
        chdir('..')
 
348
 
 
349
 
 
350
 
 
351
 
 
352
        progress("recursive and non-recursive add")
 
353
        mkdir('no-recurse')
 
354
        chdir('no-recurse')
 
355
        runbzr('init')
 
356
        mkdir('foo')
 
357
        fp = os.path.join('foo', 'test.txt')
 
358
        f = file(fp, 'w')
 
359
        f.write('hello!\n')
 
360
        f.close()
 
361
        runbzr('add --no-recurse foo')
 
362
        runbzr('file-id foo')
 
363
        runbzr('file-id ' + fp, 1)      # not versioned yet
 
364
        runbzr('commit -m add-dir-only')
 
365
 
 
366
        runbzr('file-id ' + fp, 1)      # still not versioned 
 
367
 
 
368
        runbzr('add foo')
 
369
        runbzr('file-id ' + fp)
 
370
        runbzr('commit -m add-sub-file')
 
371
 
 
372
        chdir('..')
 
373
 
 
374
 
 
375
 
 
376
class RevertCommand(InTempDir):
358
377
    def runTest(self):
359
378
        self.runbzr('init')
360
379
 
366
385
        self.runbzr('revert hello')
367
386
        self.check_file_contents('hello', 'foo')
368
387
 
 
388
    
 
389
        
 
390
 
 
391
 
 
392
# lists all tests from this module in the best order to run them.  we
 
393
# do it this way rather than just discovering them all because it
 
394
# allows us to test more basic functions first where failures will be
 
395
# easiest to understand.
 
396
TEST_CLASSES = [TestVersion,
 
397
                InitBranch,
 
398
                HelpCommands,
 
399
                UserIdentity,
 
400
                InvalidCommands,
 
401
                RevertCommand,
 
402
                OldTests,
 
403
                EmptyCommit,
 
404
                ]