~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Lalo Martins
  • Date: 2005-09-14 06:11:53 UTC
  • mto: (1185.1.22)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: lalo@exoweb.net-20050914061153-509cea89f773f329
fixing a few tests that came on the merge, for the new constructors

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
"""
28
28
 
29
29
import sys
 
30
import os
 
31
 
30
32
from bzrlib.selftest import TestCaseInTempDir, BzrTestBase
 
33
from bzrlib.branch import Branch
 
34
from bzrlib.commands import run_bzr
 
35
 
31
36
 
32
37
class ExternalBase(TestCaseInTempDir):
33
 
 
34
38
    def runbzr(self, args, retcode=0,backtick=False):
35
 
        try:
36
 
            import shutil
37
 
            from subprocess import call
38
 
        except ImportError, e:
39
 
            _need_subprocess()
40
 
            raise
41
 
 
42
39
        if isinstance(args, basestring):
43
40
            args = args.split()
44
41
 
49
46
            return self.runcmd(['python', self.BZRPATH,] + args,
50
47
                           retcode=retcode)
51
48
 
 
49
 
52
50
class TestCommands(ExternalBase):
53
51
 
54
52
    def test_help_commands(self):
59
57
        self.runbzr('commit -h')
60
58
 
61
59
    def test_init_branch(self):
62
 
        import os
63
60
        self.runbzr(['init'])
64
61
 
65
62
    def test_whoami(self):
96
93
    def test_ignore_patterns(self):
97
94
        from bzrlib.branch import Branch
98
95
        
99
 
        b = Branch('.', init=True)
 
96
        b = Branch.initialize('.')
100
97
        self.assertEquals(list(b.unknowns()), [])
101
98
 
102
99
        file('foo.tmp', 'wt').write('tmp files are ignored')
126
123
        assert file('.bzrignore', 'rb').read() == '*.blah\ngarh\n'
127
124
 
128
125
    def test_revert(self):
129
 
        import os
130
126
        self.runbzr('init')
131
127
 
132
128
        file('hello', 'wt').write('foo')
151
147
        os.rmdir('revertdir')
152
148
        self.runbzr('revert')
153
149
 
154
 
    def skipped_test_mv_modes(self):
 
150
    def test_mv_modes(self):
155
151
        """Test two modes of operation for mv"""
156
152
        from bzrlib.branch import Branch
157
 
        b = Branch('.', init=True)
 
153
        b = Branch.initialize('.')
158
154
        self.build_tree(['a', 'c', 'subdir/'])
 
155
        self.run_bzr('add', self.test_dir)
159
156
        self.run_bzr('mv', 'a', 'b')
160
157
        self.run_bzr('mv', 'b', 'subdir')
161
158
        self.run_bzr('mv', 'subdir/b', 'a')
162
 
        self.run_bzr('mv', 'a', 'b', 'subdir')
 
159
        self.run_bzr('mv', 'a', 'c', 'subdir')
163
160
        self.run_bzr('mv', 'subdir/a', 'subdir/newa')
164
161
 
 
162
 
165
163
    def test_main_version(self):
166
164
        """Check output from version command and master option is reasonable"""
167
165
        # output is intentionally passed through to stdout so that we
198
196
 
199
197
    def test_merge(self):
200
198
        from bzrlib.branch import Branch
201
 
        from bzrlib.commands import run_bzr
202
 
        import os
203
199
        
204
200
        os.mkdir('a')
205
201
        os.chdir('a')
206
 
 
207
202
        self.example_branch()
208
203
        os.chdir('..')
209
204
        self.runbzr('branch a b')
219
214
        self.runbzr('merge ../b')
220
215
        self.check_file_contents('goodbye', 'quux')
221
216
        # Merging a branch pulls its revision into the tree
222
 
        a = Branch('.')
223
 
        b = Branch('../b')
 
217
        a = Branch.open('.')
 
218
        b = Branch.open('../b')
224
219
        a.get_revision_xml(b.last_patch())
225
 
 
226
220
        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())
 
221
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
 
222
        #        % (a.pending_merges(), b.last_patch())
 
223
 
 
224
    def test_pull(self):
 
225
        """Pull changes from one branch to another."""
 
226
        os.mkdir('a')
 
227
        os.chdir('a')
 
228
 
 
229
        self.example_branch()
 
230
        os.chdir('..')
 
231
        self.runbzr('branch a b')
 
232
        os.chdir('b')
 
233
        self.runbzr('commit -m blah --unchanged')
 
234
        os.chdir('../a')
 
235
        a = Branch.open('.')
 
236
        b = Branch.open('../b')
 
237
        assert a.revision_history() == b.revision_history()[:-1]
 
238
        self.runbzr('pull ../b')
 
239
        assert a.revision_history() == b.revision_history()
 
240
        self.runbzr('commit -m blah2 --unchanged')
 
241
        os.chdir('../b')
 
242
        self.runbzr('commit -m blah3 --unchanged')
 
243
        self.runbzr('pull ../a', retcode=1)
 
244
        os.chdir('../a')
 
245
        self.runbzr('merge ../b')
 
246
        self.runbzr('commit -m blah4 --unchanged')
 
247
        os.chdir('../b')
 
248
        self.runbzr('pull ../a')
 
249
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
250
        
 
251
 
 
252
    def test_add_reports(self):
 
253
        """add command prints the names of added files."""
 
254
        b = Branch.initialize('.')
 
255
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
256
 
 
257
        from cStringIO import StringIO
 
258
        out = StringIO()
 
259
 
 
260
        ret = self.apply_redirected(None, out, None,
 
261
                                    run_bzr,
 
262
                                    ['add'])
 
263
        self.assertEquals(ret, 0)
 
264
 
 
265
        # the ordering is not defined at the moment
 
266
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
 
267
        self.assertEquals(['added dir',
 
268
                           'added dir/sub.txt',
 
269
                           'added top.txt',],
 
270
                          results)
 
271
 
229
272
 
230
273
class OldTests(ExternalBase):
231
274
    """old tests moved from ./testbzr."""
233
276
    def test_bzr(self):
234
277
        from os import chdir, mkdir
235
278
        from os.path import exists
236
 
        import os
237
279
 
238
280
        runbzr = self.runbzr
239
281
        backtick = self.backtick