~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Robert Collins
  • Date: 2005-08-23 10:44:48 UTC
  • mto: (974.1.50) (1185.1.10) (1092.3.1)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: robertc@robertcollins.net-20050823104448-fb5d448e7a5a8ee3
relace runTest with test_foo in blackbox tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
import sys
30
 
 
31
30
from bzrlib.selftest import InTempDir, BzrTestBase
32
31
 
33
32
 
34
 
 
35
33
class ExternalBase(InTempDir):
 
34
 
36
35
    def runbzr(self, args, retcode=0,backtick=False):
37
36
        try:
38
37
            import shutil
51
50
            return self.runcmd(['python', self.BZRPATH,] + args,
52
51
                           retcode=retcode)
53
52
 
54
 
 
55
 
 
56
 
class MvCommand(BzrTestBase):
57
 
    def runbzr(self):
58
 
        """Test two modes of operation for mv"""
59
 
        b = Branch('.', init=True)
60
 
        self.build_tree(['a', 'c', 'subdir/'])
61
 
        self.run_bzr('mv', 'a', 'b')
62
 
        self.run_bzr('mv', 'b', 'subdir')
63
 
        self.run_bzr('mv', 'subdir/b', 'a')
64
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
65
 
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
66
 
 
67
 
 
68
 
 
69
 
class TestVersion(BzrTestBase):
70
 
    """Check output from version command and master option is reasonable"""
71
 
    def runTest(self):
72
 
        # output is intentionally passed through to stdout so that we
73
 
        # can see the version being tested
74
 
        from cStringIO import StringIO
75
 
        save_out = sys.stdout
76
 
        try:
77
 
            sys.stdout = tmp_out = StringIO()
78
 
            
79
 
            self.run_bzr('version')
80
 
        finally:
81
 
            sys.stdout = save_out
82
 
 
83
 
        output = tmp_out.getvalue()
84
 
        self.log('bzr version output:')
85
 
        self.log(output)
86
 
        
87
 
        self.assert_(output.startswith('bzr (bazaar-ng) '))
88
 
        self.assertNotEqual(output.index('Canonical'), -1)
89
 
 
90
 
        # make sure --version is consistent
91
 
        try:
92
 
            sys.stdout = tmp_out = StringIO()
93
 
            
94
 
            self.run_bzr('--version')
95
 
        finally:
96
 
            sys.stdout = save_out
97
 
 
98
 
        self.log('bzr --version output:')
99
 
        self.log(tmp_out.getvalue())
100
 
 
101
 
        self.assertEquals(output, tmp_out.getvalue())
102
 
 
103
 
 
104
 
        
105
 
 
106
 
 
107
 
class HelpCommands(ExternalBase):
108
 
    def runTest(self):
 
53
class TestCommands(ExternalBase):
 
54
 
 
55
    def test_help_commands(self):
109
56
        self.runbzr('--help')
110
57
        self.runbzr('help')
111
58
        self.runbzr('help commands')
112
59
        self.runbzr('help help')
113
60
        self.runbzr('commit -h')
114
61
 
115
 
 
116
 
class InitBranch(ExternalBase):
117
 
    def runTest(self):
 
62
    def test_init_branch(self):
118
63
        import os
119
64
        self.runbzr(['init'])
120
65
 
121
 
 
122
 
class UserIdentity(ExternalBase):
123
 
    def runTest(self):
 
66
    def test_whoami(self):
124
67
        # this should always identify something, if only "john@localhost"
125
68
        self.runbzr("whoami")
126
69
        self.runbzr("whoami --email")
128
71
        self.assertEquals(self.runbzr("whoami --email",
129
72
                                      backtick=True).count('@'), 1)
130
73
        
131
 
class UserIdentityBranch(ExternalBase):
132
 
    def runTest(self):
133
 
        # tests branch specific user identity
 
74
    def test_whoami_branch(self):
 
75
        """branch specific user identity works."""
134
76
        self.runbzr('init')
135
77
        f = file('.bzr/email', 'wt')
136
78
        f.write('Branch Identity <branch@identi.ty>')
140
82
        self.assertTrue(whoami.startswith('Branch Identity <branch@identi.ty>'))
141
83
        self.assertTrue(whoami_email.startswith('branch@identi.ty'))
142
84
 
143
 
 
144
 
class InvalidCommands(ExternalBase):
145
 
    def runTest(self):
 
85
    def test_invalid_commands(self):
146
86
        self.runbzr("pants", retcode=1)
147
87
        self.runbzr("--pants off", retcode=1)
148
88
        self.runbzr("diff --message foo", retcode=1)
149
89
 
150
 
 
151
 
 
152
 
class EmptyCommit(ExternalBase):
153
 
    def runTest(self):
 
90
    def test_empty_commit(self):
154
91
        self.runbzr("init")
155
92
        self.build_tree(['hello.txt'])
156
93
        self.runbzr("commit -m empty", retcode=1)
157
94
        self.runbzr("add hello.txt")
158
95
        self.runbzr("commit -m added")
159
96
 
160
 
 
161
 
 
162
 
class IgnorePatterns(ExternalBase):
163
 
    def runTest(self):
 
97
    def test_ignore_patterns(self):
164
98
        from bzrlib.branch import Branch
165
99
        
166
100
        b = Branch('.', init=True)
191
125
        self.runbzr('ignore garh')
192
126
        self.assertEquals(list(b.unknowns()), [])
193
127
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
194
 
        
195
 
 
196
 
 
 
128
 
 
129
    def test_revert(self):
 
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
    def skipped_test_mv_modes(self):
 
149
        """Test two modes of operation for mv"""
 
150
        from bzrlib.branch import Branch
 
151
        b = Branch('.', init=True)
 
152
        self.build_tree(['a', 'c', 'subdir/'])
 
153
        self.run_bzr('mv', 'a', 'b')
 
154
        self.run_bzr('mv', 'b', 'subdir')
 
155
        self.run_bzr('mv', 'subdir/b', 'a')
 
156
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
157
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
 
158
 
 
159
    def test_main_version(self):
 
160
        """Check output from version command and master option is reasonable"""
 
161
        # output is intentionally passed through to stdout so that we
 
162
        # can see the version being tested
 
163
        output = self.runbzr('version', backtick=1)
 
164
        self.log('bzr version output:')
 
165
        self.log(output)
 
166
        self.assert_(output.startswith('bzr (bazaar-ng) '))
 
167
        self.assertNotEqual(output.index('Canonical'), -1)
 
168
        # make sure --version is consistent
 
169
        tmp_output = self.runbzr('--version', backtick=1)
 
170
        self.log('bzr --version output:')
 
171
        self.log(tmp_output)
 
172
        self.assertEquals(output, tmp_output)
197
173
 
198
174
class OldTests(ExternalBase):
199
175
    # old tests moved from ./testbzr
200
 
    def runTest(self):
 
176
    def test_bzr(self):
201
177
        from os import chdir, mkdir
202
178
        from os.path import exists
203
179
        import os
366
342
        runbzr('info')
367
343
 
368
344
 
369
 
 
370
 
 
371
 
 
372
 
 
373
 
class RevertCommand(ExternalBase):
374
 
    def runTest(self):
375
 
        self.runbzr('init')
376
 
 
377
 
        file('hello', 'wt').write('foo')
378
 
        self.runbzr('add hello')
379
 
        self.runbzr('commit -m setup hello')
380
 
 
381
 
        file('goodbye', 'wt').write('baz')
382
 
        self.runbzr('add goodbye')
383
 
        self.runbzr('commit -m setup goodbye')
384
 
        
385
 
        file('hello', 'wt').write('bar')
386
 
        file('goodbye', 'wt').write('qux')
387
 
        self.runbzr('revert hello')
388
 
        self.check_file_contents('hello', 'foo')
389
 
        self.check_file_contents('goodbye', 'qux')
390
 
        self.runbzr('revert')
391
 
        self.check_file_contents('goodbye', 'baz')
392