/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: A. S. Budden
  • Date: 2011-05-04 13:26:14 UTC
  • mto: (5816.6.16 bazaar_source)
  • mto: This revision was merged to the branch mainline in revision 5835.
  • Revision ID: abudden@gmail.com-20110504132614-3ghb1ajucl6plc5z
Set the parent location of the bound branch to that of the master branch.

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.blackbox import ExternalBase
 
29
from bzrlib.tests import (
 
30
        TestCaseWithTransport,
 
31
        script,
 
32
        )
26
33
from bzrlib.directory_service import directories
27
34
 
28
 
 
29
 
class TestSwitch(ExternalBase):
 
35
class TestSwitch(TestCaseWithTransport):
30
36
 
31
37
    def _create_sample_tree(self):
32
38
        tree = self.make_branch_and_tree('branch-1')
129
135
        """Using switch on a heavy checkout should find master sibling
130
136
 
131
137
        The behaviour of lighweight and heavy checkouts should be
132
 
        consistentwhen using the convenient "switch to sibling" feature
 
138
        consistent when using the convenient "switch to sibling" feature
133
139
        Both should switch to a sibling of the branch
134
140
        they are bound to, and not a sibling of themself"""
135
141
 
149
155
        tree = self._create_sample_tree()
150
156
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
151
157
        self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
152
 
        self.failUnlessExists('checkout/file-1')
153
 
        self.failIfExists('checkout/file-2')
 
158
        self.assertPathExists('checkout/file-1')
 
159
        self.assertPathDoesNotExist('checkout/file-2')
154
160
 
155
161
    def test_switch_only_revision(self):
156
162
        tree = self._create_sample_tree()
157
163
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
 
        self.failUnlessExists('checkout/file-1')
159
 
        self.failUnlessExists('checkout/file-2')
 
164
        self.assertPathExists('checkout/file-1')
 
165
        self.assertPathExists('checkout/file-2')
160
166
        self.run_bzr(['switch', '-r1'], working_dir='checkout')
161
 
        self.failUnlessExists('checkout/file-1')
162
 
        self.failIfExists('checkout/file-2')
 
167
        self.assertPathExists('checkout/file-1')
 
168
        self.assertPathDoesNotExist('checkout/file-2')
163
169
        # Check that we don't accept a range
164
170
        self.run_bzr_error(
165
171
            ['bzr switch --revision takes exactly one revision identifier'],
252
258
        self.assertLength(0, calls)
253
259
        out, err = self.run_bzr('switch ../branch2')
254
260
        self.assertLength(1, calls)
 
261
 
 
262
    def test_switch_lightweight_directory(self):
 
263
        """Test --directory option"""
 
264
 
 
265
        # create a source branch
 
266
        a_tree = self.make_branch_and_tree('a')
 
267
        self.build_tree_contents([('a/a', 'initial\n')])
 
268
        a_tree.add('a')
 
269
        a_tree.commit(message='initial')
 
270
 
 
271
        # clone and add a differing revision
 
272
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
 
273
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
 
274
        b_tree.commit(message='more')
 
275
 
 
276
        self.run_bzr('checkout --lightweight a checkout')
 
277
        self.run_bzr('switch --directory checkout b')
 
278
        self.assertFileEqual('initial\nmore\n', 'checkout/a')
 
279
 
 
280
 
 
281
class TestSwitchParentLocation(TestCaseWithTransport):
 
282
 
 
283
    def setUp(self):
 
284
        """Set up a repository and branch ready for testing."""
 
285
        super(TestSwitchParentLocation, 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 assertParentCorrect(self, branch, expected_parent, name):
 
298
        """Verify that the parent is not None and is set correctly."""
 
299
        actual_parent = branch.get_parent()
 
300
        self.assertIsNot(actual_parent, None, name + "Parent not set")
 
301
        expected = urlutils.strip_trailing_slash(urlutils.normalize_url(expected_parent))
 
302
        actual = urlutils.strip_trailing_slash(urlutils.normalize_url(actual_parent))
 
303
        self.assertEquals(expected, actual, name + "Parent set incorrectly")
 
304
 
 
305
    def _create_checkout_and_switch(self, option, suffix):
 
306
        self.script_runner.run_script(self, '''
 
307
                $ bzr checkout %(option)s repo/trunk work_%(suffix)s_switch
 
308
                $ cd work_%(suffix)s_switch
 
309
                $ bzr switch --create-branch switched_%(suffix)s
 
310
                2>Tree is up to date at revision 0.
 
311
                2>Switched to branch:...switched_%(suffix)s...
 
312
                $ cd ..
 
313
                ''' % locals())
 
314
        bound_branch = branch.Branch.open_containing('work_%(suffix)s_switch' % locals())[0]
 
315
        master_branch = branch.Branch.open_containing('repo/switched_%(suffix)s' % locals())[0]
 
316
        return (bound_branch, master_branch)
 
317
 
 
318
    def test_switch_parent_lightweight(self):
 
319
        """Verify parent directory for lightweight checkout using bzr switch."""
 
320
        bb, mb = self._create_checkout_and_switch(option='--lightweight', suffix='lw')
 
321
        self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Checkout")
 
322
        self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
 
323
 
 
324
    def test_switch_parent_heavyweight(self):
 
325
        """Verify parent directory for heavyweight checkout using bzr switch."""
 
326
        bb, mb = self._create_checkout_and_switch(option='', suffix='hw')
 
327
        self.assertParentCorrect(bb, urlutils.local_path_to_url('repo/trunk'), "Bound Branch")
 
328
        self.assertParentCorrect(mb, urlutils.local_path_to_url('repo/trunk'), "Master Branch")
 
329