~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_switch.py

  • Committer: Vincent Ladeuil
  • Date: 2011-05-15 16:07:11 UTC
  • mto: (5743.13.4 config-editor-option)
  • mto: This revision was merged to the branch mainline in revision 5944.
  • Revision ID: v.ladeuil+lp@free.fr-20110515160711-l0og3ady9wuahz1k
Stack.get() provides the registered option default value.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import osutils
 
23
from bzrlib import (
 
24
        osutils,
 
25
        urlutils,
 
26
        branch,
 
27
        )
24
28
from bzrlib.workingtree import WorkingTree
25
 
from bzrlib.tests import TestCaseWithTransport
 
29
from bzrlib.tests import (
 
30
        TestCaseWithTransport,
 
31
        script,
 
32
        )
26
33
from bzrlib.directory_service import directories
27
34
 
28
35
 
129
136
        """Using switch on a heavy checkout should find master sibling
130
137
 
131
138
        The behaviour of lighweight and heavy checkouts should be
132
 
        consistentwhen using the convenient "switch to sibling" feature
 
139
        consistent when using the convenient "switch to sibling" feature
133
140
        Both should switch to a sibling of the branch
134
141
        they are bound to, and not a sibling of themself"""
135
142
 
149
156
        tree = self._create_sample_tree()
150
157
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
151
158
        self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
152
 
        self.failUnlessExists('checkout/file-1')
153
 
        self.failIfExists('checkout/file-2')
 
159
        self.assertPathExists('checkout/file-1')
 
160
        self.assertPathDoesNotExist('checkout/file-2')
154
161
 
155
162
    def test_switch_only_revision(self):
156
163
        tree = self._create_sample_tree()
157
164
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
 
        self.failUnlessExists('checkout/file-1')
159
 
        self.failUnlessExists('checkout/file-2')
 
165
        self.assertPathExists('checkout/file-1')
 
166
        self.assertPathExists('checkout/file-2')
160
167
        self.run_bzr(['switch', '-r1'], working_dir='checkout')
161
 
        self.failUnlessExists('checkout/file-1')
162
 
        self.failIfExists('checkout/file-2')
 
168
        self.assertPathExists('checkout/file-1')
 
169
        self.assertPathDoesNotExist('checkout/file-2')
163
170
        # Check that we don't accept a range
164
171
        self.run_bzr_error(
165
172
            ['bzr switch --revision takes exactly one revision identifier'],
270
277
        self.run_bzr('checkout --lightweight a checkout')
271
278
        self.run_bzr('switch --directory checkout b')
272
279
        self.assertFileEqual('initial\nmore\n', 'checkout/a')
 
280
 
 
281
class TestSwitchParentLocationBase(TestCaseWithTransport):
 
282
 
 
283
    def setUp(self):
 
284
        """Set up a repository and branch ready for testing."""
 
285
        super(TestSwitchParentLocationBase, self).setUp()
 
286
        self.script_runner = script.ScriptRunner()
 
287
        self.script_runner.run_script(self, '''
 
288
                $ bzr init-repo --no-trees repo
 
289
                Shared repository...
 
290
                Location:
 
291
                  shared repository: repo
 
292
                $ bzr init repo/trunk
 
293
                Created a repository branch...
 
294
                Using shared repository: ...
 
295
                ''')
 
296
 
 
297
    def assertParent(self, expected_parent, branch):
 
298
        """Verify that the parent is not None and is set correctly."""
 
299
        actual_parent = branch.get_parent()
 
300
        self.assertIsSameRealPath(urlutils.local_path_to_url(expected_parent),
 
301
                                  branch.get_parent())
 
302
 
 
303
 
 
304
class TestSwitchParentLocation(TestSwitchParentLocationBase):
 
305
 
 
306
    def _checkout_and_switch(self, option=''):
 
307
        self.script_runner.run_script(self, '''
 
308
                $ bzr checkout %(option)s repo/trunk checkout
 
309
                $ cd checkout
 
310
                $ bzr switch --create-branch switched
 
311
                2>Tree is up to date at revision 0.
 
312
                2>Switched to branch:...switched...
 
313
                $ cd ..
 
314
                ''' % locals())
 
315
        bound_branch = branch.Branch.open_containing('checkout')[0]
 
316
        master_branch = branch.Branch.open_containing('repo/switched')[0]
 
317
        return (bound_branch, master_branch)
 
318
 
 
319
    def test_switch_parent_lightweight(self):
 
320
        """Lightweight checkout using bzr switch."""
 
321
        bb, mb = self._checkout_and_switch(option='--lightweight')
 
322
        self.assertParent('repo/trunk', bb)
 
323
        self.assertParent('repo/trunk', mb)
 
324
 
 
325
    def test_switch_parent_heavyweight(self):
 
326
        """Heavyweight checkout using bzr switch."""
 
327
        bb, mb = self._checkout_and_switch()
 
328
        self.assertParent('repo/trunk', bb)
 
329
        self.assertParent('repo/trunk', mb)
 
330