~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-25 01:56:02 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-20050825015601-b4ac37f043068e82
break smart_add into smart_add and smart_add_branch which will accept a branch parameter

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 TestCaseInTempDir, BzrTestBase
32
 
from bzrlib.branch import Branch
33
 
from bzrlib.commands import run_bzr
34
 
 
35
 
 
36
 
class ExternalBase(TestCaseInTempDir):
 
30
from bzrlib.selftest import InTempDir, BzrTestBase
 
31
 
 
32
 
 
33
class ExternalBase(InTempDir):
 
34
 
37
35
    def runbzr(self, args, retcode=0,backtick=False):
 
36
        try:
 
37
            import shutil
 
38
            from subprocess import call
 
39
        except ImportError, e:
 
40
            _need_subprocess()
 
41
            raise
 
42
 
38
43
        if isinstance(args, basestring):
39
44
            args = args.split()
40
45
 
45
50
            return self.runcmd(['python', self.BZRPATH,] + args,
46
51
                           retcode=retcode)
47
52
 
48
 
 
49
53
class TestCommands(ExternalBase):
50
54
 
51
55
    def test_help_commands(self):
56
60
        self.runbzr('commit -h')
57
61
 
58
62
    def test_init_branch(self):
 
63
        import os
59
64
        self.runbzr(['init'])
60
65
 
61
66
    def test_whoami(self):
173
178
        self.log(tmp_output)
174
179
        self.assertEquals(output, tmp_output)
175
180
 
176
 
    def example_branch(test):
177
 
        test.runbzr('init')
178
 
        file('hello', 'wt').write('foo')
179
 
        test.runbzr('add hello')
180
 
        test.runbzr('commit -m setup hello')
181
 
        file('goodbye', 'wt').write('baz')
182
 
        test.runbzr('add goodbye')
183
 
        test.runbzr('commit -m setup goodbye')
184
 
 
185
 
    def test_revert(self):
186
 
        self.example_branch()
187
 
        file('hello', 'wt').write('bar')
188
 
        file('goodbye', 'wt').write('qux')
189
 
        self.runbzr('revert hello')
190
 
        self.check_file_contents('hello', 'foo')
191
 
        self.check_file_contents('goodbye', 'qux')
192
 
        self.runbzr('revert')
193
 
        self.check_file_contents('goodbye', 'baz')
194
 
 
195
 
    def test_merge(self):
196
 
        from bzrlib.branch import Branch
197
 
        import os
198
 
        
199
 
        os.mkdir('a')
200
 
        os.chdir('a')
201
 
 
202
 
        self.example_branch()
203
 
        os.chdir('..')
204
 
        self.runbzr('branch a b')
205
 
        os.chdir('b')
206
 
        file('goodbye', 'wt').write('quux')
207
 
        self.runbzr(['commit',  '-m',  "more u's are always good"])
208
 
 
209
 
        os.chdir('../a')
210
 
        file('hello', 'wt').write('quuux')
211
 
        # We can't merge when there are in-tree changes
212
 
        self.runbzr('merge ../b', retcode=1)
213
 
        self.runbzr(['commit', '-m', "Like an epidemic of u's"])
214
 
        self.runbzr('merge ../b')
215
 
        self.check_file_contents('goodbye', 'quux')
216
 
        # Merging a branch pulls its revision into the tree
217
 
        a = Branch('.')
218
 
        b = Branch('../b')
219
 
        a.get_revision_xml(b.last_patch())
220
 
 
221
 
        self.log('pending merges: %s', a.pending_merges())
222
 
        #        assert a.pending_merges() == [b.last_patch()], "Assertion %s %s" \
223
 
        #        % (a.pending_merges(), b.last_patch())
224
 
 
225
 
 
226
 
    def test_add_reports(self):
227
 
        """add command prints the names of added files."""
228
 
        b = Branch('.', init=True)
229
 
        self.build_tree(['top.txt', 'dir/', 'dir/sub.txt'])
230
 
 
231
 
        from cStringIO import StringIO
232
 
        out = StringIO()
233
 
 
234
 
        ret = self.apply_redirected(None, out, None,
235
 
                                    run_bzr,
236
 
                                    ['add'])
237
 
        self.assertEquals(ret, 0)
238
 
 
239
 
        # the ordering is not defined at the moment
240
 
        results = sorted(out.getvalue().rstrip('\n').split('\n'))
241
 
        self.assertEquals(['added dir',
242
 
                           'added dir/sub.txt',
243
 
                           'added top.txt',],
244
 
                          results)
245
 
 
246
 
 
247
181
class OldTests(ExternalBase):
248
 
    """old tests moved from ./testbzr."""
249
 
 
 
182
    # old tests moved from ./testbzr
250
183
    def test_bzr(self):
251
184
        from os import chdir, mkdir
252
185
        from os.path import exists
414
347
        runbzr('log --forward')
415
348
 
416
349
        runbzr('info')
417