/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-06-21 06:10:18 UTC
  • Revision ID: mbp@sourcefrog.net-20050621061017-12e8f0ff45228338
- move whitebox/blackbox modules into bzrlib.selftest subdirectory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 by Canonical Ltd
2
 
# -*- coding: utf-8 -*-
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
20
19
 
21
20
These check that it behaves properly when it's invoked through the regular
22
21
command-line interface.
23
 
 
24
 
This always reinvokes bzr through a new Python interpreter, which is a
25
 
bit inefficient but arguably tests in a way more representative of how
26
 
it's normally invoked.
27
22
"""
28
23
 
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):
37
 
        try:
38
 
            import shutil
39
 
            from subprocess import call
40
 
        except ImportError, e:
41
 
            _need_subprocess()
42
 
            raise
43
 
 
44
 
        if isinstance(args, basestring):
45
 
            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"""
 
24
# this code was previously in testbzr
 
25
 
 
26
from unittest import TestCase
 
27
from bzrlib.selftest import TestBase
 
28
 
 
29
class TestVersion(TestBase):
67
30
    def runTest(self):
68
31
        # output is intentionally passed through to stdout so that we
69
32
        # 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):
105
 
        self.runbzr('--help')
106
 
        self.runbzr('help')
107
 
        self.runbzr('help commands')
108
 
        self.runbzr('help help')
109
 
        self.runbzr('commit -h')
110
 
 
111
 
 
112
 
class InitBranch(ExternalBase):
113
 
    def runTest(self):
114
 
        import os
115
 
        self.runbzr(['init'])
116
 
 
117
 
 
118
 
 
119
 
class UserIdentity(ExternalBase):
120
 
    def runTest(self):
121
 
        # this should always identify something, if only "john@localhost"
122
 
        self.runbzr("whoami")
123
 
        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):
130
 
        self.runbzr("pants", retcode=1)
131
 
        self.runbzr("--pants off", retcode=1)
132
 
        self.runbzr("diff --message foo", retcode=1)
133
 
 
134
 
 
135
 
 
136
 
class EmptyCommit(ExternalBase):
137
 
    def runTest(self):
138
 
        self.runbzr("init")
139
 
        self.build_tree(['hello.txt'])
140
 
        self.runbzr("commit -m empty", retcode=1)
141
 
        self.runbzr("add hello.txt")
142
 
        self.runbzr("commit -m added")
143
 
 
144
 
 
145
 
 
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):
183
 
    # old tests moved from ./testbzr
184
 
    def runTest(self):
185
 
        from os import chdir, mkdir
186
 
        from os.path import exists
187
 
        import os
188
 
 
189
 
        runbzr = self.runbzr
190
 
        backtick = self.backtick
191
 
        progress = self.log
192
 
 
193
 
        progress("basic branch creation")
194
 
        mkdir('branch1')
195
 
        chdir('branch1')
196
 
        runbzr('init')
197
 
 
198
 
        self.assertEquals(backtick('bzr root').rstrip(),
199
 
                          os.path.join(self.test_dir, 'branch1'))
200
 
 
201
 
        progress("status of new file")
202
 
 
203
 
        f = file('test.txt', 'wt')
204
 
        f.write('hello world!\n')
205
 
        f.close()
206
 
 
207
 
        out = backtick("bzr unknowns")
208
 
        self.assertEquals(out, 'test.txt\n')
209
 
 
210
 
        out = backtick("bzr status")
211
 
        assert out == 'unknown:\n  test.txt\n'
212
 
 
213
 
        out = backtick("bzr status --all")
214
 
        assert out == "unknown:\n  test.txt\n"
215
 
 
216
 
        out = backtick("bzr status test.txt --all")
217
 
        assert out == "unknown:\n  test.txt\n"
218
 
 
219
 
        f = file('test2.txt', 'wt')
220
 
        f.write('goodbye cruel world...\n')
221
 
        f.close()
222
 
 
223
 
        out = backtick("bzr status test.txt")
224
 
        assert out == "unknown:\n  test.txt\n"
225
 
 
226
 
        out = backtick("bzr status")
227
 
        assert out == ("unknown:\n"
228
 
                       "  test.txt\n"
229
 
                       "  test2.txt\n")
230
 
 
231
 
        os.unlink('test2.txt')
232
 
 
233
 
        progress("command aliases")
234
 
        out = backtick("bzr st --all")
235
 
        assert out == ("unknown:\n"
236
 
                       "  test.txt\n")
237
 
 
238
 
        out = backtick("bzr stat")
239
 
        assert out == ("unknown:\n"
240
 
                       "  test.txt\n")
241
 
 
242
 
        progress("command help")
243
 
        runbzr("help st")
244
 
        runbzr("help")
245
 
        runbzr("help commands")
246
 
        runbzr("help slartibartfast", 1)
247
 
 
248
 
        out = backtick("bzr help ci")
249
 
        out.index('aliases: ')
250
 
 
251
 
        progress("can't rename unversioned file")
252
 
        runbzr("rename test.txt new-test.txt", 1)
253
 
 
254
 
        progress("adding a file")
255
 
 
256
 
        runbzr("add test.txt")
257
 
        assert backtick("bzr unknowns") == ''
258
 
        assert backtick("bzr status --all") == ("added:\n"
259
 
                                                "  test.txt\n")
260
 
 
261
 
        progress("rename newly-added file")
262
 
        runbzr("rename test.txt hello.txt")
263
 
        assert os.path.exists("hello.txt")
264
 
        assert not os.path.exists("test.txt")
265
 
 
266
 
        assert backtick("bzr revno") == '0\n'
267
 
 
268
 
        progress("add first revision")
269
 
        runbzr(['commit', '-m', 'add first revision'])
270
 
 
271
 
        progress("more complex renames")
272
 
        os.mkdir("sub1")
273
 
        runbzr("rename hello.txt sub1", 1)
274
 
        runbzr("rename hello.txt sub1/hello.txt", 1)
275
 
        runbzr("move hello.txt sub1", 1)
276
 
 
277
 
        runbzr("add sub1")
278
 
        runbzr("rename sub1 sub2")
279
 
        runbzr("move hello.txt sub2")
280
 
        assert backtick("bzr relpath sub2/hello.txt") == os.path.join("sub2", "hello.txt\n")
281
 
 
282
 
        assert exists("sub2")
283
 
        assert exists("sub2/hello.txt")
284
 
        assert not exists("sub1")
285
 
        assert not exists("hello.txt")
286
 
 
287
 
        runbzr(['commit', '-m', 'commit with some things moved to subdirs'])
288
 
 
289
 
        mkdir("sub1")
290
 
        runbzr('add sub1')
291
 
        runbzr('move sub2/hello.txt sub1')
292
 
        assert not exists('sub2/hello.txt')
293
 
        assert exists('sub1/hello.txt')
294
 
        runbzr('move sub2 sub1')
295
 
        assert not exists('sub2')
296
 
        assert exists('sub1/sub2')
297
 
 
298
 
        runbzr(['commit', '-m', 'rename nested subdirectories'])
299
 
 
300
 
        chdir('sub1/sub2')
301
 
        self.assertEquals(backtick('bzr root')[:-1],
302
 
                          os.path.join(self.test_dir, 'branch1'))
303
 
        runbzr('move ../hello.txt .')
304
 
        assert exists('./hello.txt')
305
 
        assert backtick('bzr relpath hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
306
 
        assert backtick('bzr relpath ../../sub1/sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
307
 
        runbzr(['commit', '-m', 'move to parent directory'])
308
 
        chdir('..')
309
 
        assert backtick('bzr relpath sub2/hello.txt') == os.path.join('sub1', 'sub2', 'hello.txt\n')
310
 
 
311
 
        runbzr('move sub2/hello.txt .')
312
 
        assert exists('hello.txt')
313
 
 
314
 
        f = file('hello.txt', 'wt')
315
 
        f.write('some nice new content\n')
316
 
        f.close()
317
 
 
318
 
        f = file('msg.tmp', 'wt')
319
 
        f.write('this is my new commit\n')
320
 
        f.close()
321
 
 
322
 
        runbzr('commit -F msg.tmp')
323
 
 
324
 
        assert backtick('bzr revno') == '5\n'
325
 
        runbzr('export -r 5 export-5.tmp')
326
 
        runbzr('export export.tmp')
327
 
 
328
 
        runbzr('log')
329
 
        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')
337
 
 
338
 
 
339
 
        progress("file with spaces in name")
340
 
        mkdir('sub directory')
341
 
        file('sub directory/file with spaces ', 'wt').write('see how this works\n')
342
 
        runbzr('add .')
343
 
        runbzr('diff')
344
 
        runbzr('commit -m add-spaces')
345
 
        runbzr('check')
346
 
 
347
 
        runbzr('log')
348
 
        runbzr('log --forward')
349
 
 
350
 
        runbzr('info')
351
 
 
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
 
 
 
33
        self.runcmd(['bzr', 'version'])
 
34
 
 
35
 
 
36
# class InTempBranch(TestBase):
 
37
#     """Base class for tests run in a temporary branch."""
 
38
#     def setUp():
 
39
#     def tearDown()
 
40
 
 
41
 
 
42
# class InitBranch(TestBase):
 
43
#     def runTest(self):
 
44