/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-08-30 01:35:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050830013540-34e8996a86ba25fb
- rename FunctionalTest to TestCaseInTempDir

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
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):
 
30
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
31
 
 
32
class ExternalBase(TestCaseInTempDir):
 
33
 
 
34
    def runbzr(self, args, retcode=0,backtick=False):
37
35
        try:
38
36
            import shutil
39
37
            from subprocess import call
43
41
 
44
42
        if isinstance(args, basestring):
45
43
            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):
 
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):
105
55
        self.runbzr('--help')
106
56
        self.runbzr('help')
107
57
        self.runbzr('help commands')
108
58
        self.runbzr('help help')
109
59
        self.runbzr('commit -h')
110
60
 
111
 
 
112
 
class InitBranch(ExternalBase):
113
 
    def runTest(self):
 
61
    def test_init_branch(self):
114
62
        import os
115
63
        self.runbzr(['init'])
116
64
 
117
 
 
118
 
 
119
 
class UserIdentity(ExternalBase):
120
 
    def runTest(self):
 
65
    def test_whoami(self):
121
66
        # this should always identify something, if only "john@localhost"
122
67
        self.runbzr("whoami")
123
68
        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):
 
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):
130
85
        self.runbzr("pants", retcode=1)
131
86
        self.runbzr("--pants off", retcode=1)
132
87
        self.runbzr("diff --message foo", retcode=1)
133
88
 
134
 
 
135
 
 
136
 
class EmptyCommit(ExternalBase):
137
 
    def runTest(self):
 
89
    def test_empty_commit(self):
138
90
        self.runbzr("init")
139
91
        self.build_tree(['hello.txt'])
140
92
        self.runbzr("commit -m empty", retcode=1)
141
93
        self.runbzr("add hello.txt")
142
94
        self.runbzr("commit -m added")
143
95
 
144
 
 
145
 
 
146
 
class IgnorePatterns(ExternalBase):
147
 
    def runTest(self):
 
96
    def test_ignore_patterns(self):
148
97
        from bzrlib.branch import Branch
149
98
        
150
99
        b = Branch('.', init=True)
175
124
        self.runbzr('ignore garh')
176
125
        self.assertEquals(list(b.unknowns()), [])
177
126
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
178
 
        
179
 
 
180
 
 
 
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())
181
229
 
182
230
class OldTests(ExternalBase):
183
 
    # old tests moved from ./testbzr
184
 
    def runTest(self):
 
231
    """old tests moved from ./testbzr."""
 
232
 
 
233
    def test_bzr(self):
185
234
        from os import chdir, mkdir
186
235
        from os.path import exists
187
236
        import os
349
398
 
350
399
        runbzr('info')
351
400
 
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