~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/blackbox.py

  • Committer: Martin Pool
  • Date: 2005-09-13 23:42:32 UTC
  • mto: (1185.8.2) (974.1.91)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: mbp@sourcefrog.net-20050913234232-4d901f2d843a35f3
- ignore .DS_Store by default

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):
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')
198
194
 
199
195
    def test_merge(self):
200
196
        from bzrlib.branch import Branch
201
 
        from bzrlib.commands import run_bzr
202
 
        import os
203
197
        
204
198
        os.mkdir('a')
205
199
        os.chdir('a')
224
218
        a.get_revision_xml(b.last_patch())
225
219
 
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
        self.runbzr('pull', retcode=1)
 
231
        self.runbzr('missing', retcode=1)
 
232
        self.runbzr('missing .')
 
233
        self.runbzr('missing')
 
234
        self.runbzr('pull')
 
235
        self.runbzr('pull /', retcode=1)
 
236
        self.runbzr('pull')
 
237
 
 
238
        os.chdir('..')
 
239
        self.runbzr('branch a b')
 
240
        os.chdir('b')
 
241
        self.runbzr('pull')
 
242
        self.runbzr('commit -m blah --unchanged')
 
243
        os.chdir('../a')
 
244
        a = Branch('.')
 
245
        b = Branch('../b')
 
246
        assert a.revision_history() == b.revision_history()[:-1]
 
247
        self.runbzr('pull ../b')
 
248
        assert a.revision_history() == b.revision_history()
 
249
        self.runbzr('commit -m blah2 --unchanged')
 
250
        os.chdir('../b')
 
251
        self.runbzr('commit -m blah3 --unchanged')
 
252
        self.runbzr('pull ../a', retcode=1)
 
253
        os.chdir('../a')
 
254
        self.runbzr('merge ../b')
 
255
        self.runbzr('commit -m blah4 --unchanged')
 
256
        os.chdir('../b')
 
257
        self.runbzr('pull ../a')
 
258
        assert a.revision_history()[-1] == b.revision_history()[-1]
 
259
        
 
260
 
 
261
    def test_add_reports(self):
 
262
        """add command prints the names of added files."""
 
263
        b = Branch('.', init=True)
 
264
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
 
265
 
 
266
        from cStringIO import StringIO
 
267
        out = StringIO()
 
268
 
 
269
        ret = self.apply_redirected(None, out, None,
 
270
                                    run_bzr,
 
271
                                    ['add'])
 
272
        self.assertEquals(ret, 0)
 
273
 
 
274
        # the ordering is not defined at the moment
 
275
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
 
276
        self.assertEquals(['added dir',
 
277
                           'added dir/sub.txt',
 
278
                           'added top.txt',],
 
279
                          results)
 
280
 
229
281
 
230
282
class OldTests(ExternalBase):
231
283
    """old tests moved from ./testbzr."""
233
285
    def test_bzr(self):
234
286
        from os import chdir, mkdir
235
287
        from os.path import exists
236
 
        import os
237
288
 
238
289
        runbzr = self.runbzr
239
290
        backtick = self.backtick