~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-06 06:59:03 UTC
  • mfrom: (5051.5.1 subunit)
  • Revision ID: pqm@pqm.ubuntu.com-20100406065903-y9dxgwmog1pmw7dz
Use subunit when running tests in PQM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import (
24
 
        osutils,
25
 
        urlutils,
26
 
        branch,
27
 
        )
28
23
from bzrlib.workingtree import WorkingTree
29
 
from bzrlib.tests import (
30
 
        TestCaseWithTransport,
31
 
        script,
32
 
        )
 
24
from bzrlib.tests.blackbox import ExternalBase
33
25
from bzrlib.directory_service import directories
34
26
 
35
27
 
36
 
class TestSwitch(TestCaseWithTransport):
 
28
class TestSwitch(ExternalBase):
37
29
 
38
30
    def _create_sample_tree(self):
39
31
        tree = self.make_branch_and_tree('branch-1')
136
128
        """Using switch on a heavy checkout should find master sibling
137
129
 
138
130
        The behaviour of lighweight and heavy checkouts should be
139
 
        consistent when using the convenient "switch to sibling" feature
 
131
        consistentwhen using the convenient "switch to sibling" feature
140
132
        Both should switch to a sibling of the branch
141
133
        they are bound to, and not a sibling of themself"""
142
134
 
156
148
        tree = self._create_sample_tree()
157
149
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
158
150
        self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
159
 
        self.assertPathExists('checkout/file-1')
160
 
        self.assertPathDoesNotExist('checkout/file-2')
 
151
        self.failUnlessExists('checkout/file-1')
 
152
        self.failIfExists('checkout/file-2')
161
153
 
162
154
    def test_switch_only_revision(self):
163
155
        tree = self._create_sample_tree()
164
156
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
165
 
        self.assertPathExists('checkout/file-1')
166
 
        self.assertPathExists('checkout/file-2')
 
157
        self.failUnlessExists('checkout/file-1')
 
158
        self.failUnlessExists('checkout/file-2')
167
159
        self.run_bzr(['switch', '-r1'], working_dir='checkout')
168
 
        self.assertPathExists('checkout/file-1')
169
 
        self.assertPathDoesNotExist('checkout/file-2')
 
160
        self.failUnlessExists('checkout/file-1')
 
161
        self.failIfExists('checkout/file-2')
170
162
        # Check that we don't accept a range
171
163
        self.run_bzr_error(
172
164
            ['bzr switch --revision takes exactly one revision identifier'],
175
167
    def prepare_lightweight_switch(self):
176
168
        branch = self.make_branch('branch')
177
169
        branch.create_checkout('tree', lightweight=True)
178
 
        osutils.rename('branch', 'branch1')
 
170
        os.rename('branch', 'branch1')
179
171
 
180
172
    def test_switch_lightweight_after_branch_moved(self):
181
173
        self.prepare_lightweight_switch()
233
225
        self.run_bzr('switch -b foo:branch2', working_dir='tree')
234
226
        tree = WorkingTree.open('tree')
235
227
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')
236
 
 
237
 
    def test_switch_with_post_switch_hook(self):
238
 
        from bzrlib import branch as _mod_branch
239
 
        calls = []
240
 
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
241
 
            calls.append, None)
242
 
        self.make_branch_and_tree('branch')
243
 
        self.run_bzr('branch branch branch2')
244
 
        self.run_bzr('checkout branch checkout')
245
 
        os.chdir('checkout')
246
 
        self.assertLength(0, calls)
247
 
        out, err = self.run_bzr('switch ../branch2')
248
 
        self.assertLength(1, calls)
249
 
 
250
 
    def test_switch_lightweight_co_with_post_switch_hook(self):
251
 
        from bzrlib import branch as _mod_branch
252
 
        calls = []
253
 
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
254
 
            calls.append, None)
255
 
        self.make_branch_and_tree('branch')
256
 
        self.run_bzr('branch branch branch2')
257
 
        self.run_bzr('checkout --lightweight branch checkout')
258
 
        os.chdir('checkout')
259
 
        self.assertLength(0, calls)
260
 
        out, err = self.run_bzr('switch ../branch2')
261
 
        self.assertLength(1, calls)
262
 
 
263
 
    def test_switch_lightweight_directory(self):
264
 
        """Test --directory option"""
265
 
 
266
 
        # create a source branch
267
 
        a_tree = self.make_branch_and_tree('a')
268
 
        self.build_tree_contents([('a/a', 'initial\n')])
269
 
        a_tree.add('a')
270
 
        a_tree.commit(message='initial')
271
 
 
272
 
        # clone and add a differing revision
273
 
        b_tree = a_tree.bzrdir.sprout('b').open_workingtree()
274
 
        self.build_tree_contents([('b/a', 'initial\nmore\n')])
275
 
        b_tree.commit(message='more')
276
 
 
277
 
        self.run_bzr('checkout --lightweight a checkout')
278
 
        self.run_bzr('switch --directory checkout b')
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