~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: 2016-02-07 18:23:13 UTC
  • mto: (6615.3.1 2.7)
  • mto: This revision was merged to the branch mainline in revision 6620.
  • Revision ID: v.ladeuil+lp@free.fr-20160207182313-jwz7z3vj4mpyjn7y
Ensure http://pad.lv/1323805 won't come back.

Since the 2.6.0 release pypi policy changed and release tarballs can't be
hosted on launchpad anymore, they have to be uploaded to
http://pypi.python.org/pypi


This fixes setup.py sdist to generate the right tarball with nearly the same
content as the one produced for 2.7.0.

Such a tarball have been uploaded to pypi properly signed and tested for
installation in venv.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2012, 2016 Canonical Ltd
2
2
# -*- coding: utf-8 -*-
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib.bzrdir import BzrDir
 
23
from bzrlib.controldir import ControlDir
24
24
from bzrlib import (
25
 
        osutils,
26
 
        urlutils,
27
 
        branch,
28
 
        )
 
25
    osutils,
 
26
    urlutils,
 
27
    branch,
 
28
    )
29
29
from bzrlib.workingtree import WorkingTree
30
30
from bzrlib.tests import (
31
 
        TestCaseWithTransport,
32
 
        script,
33
 
        )
 
31
    TestCaseWithTransport,
 
32
    script,
 
33
    )
34
34
from bzrlib.tests.features import UnicodeFilenameFeature
35
35
from bzrlib.directory_service import directories
36
36
 
 
37
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
38
 
37
39
 
38
40
class TestSwitch(TestCaseWithTransport):
39
41
 
151
153
        branchb_id = tree2.commit('bar')
152
154
        checkout = tree1.branch.create_checkout('heavyco/a', lightweight=False)
153
155
        self.run_bzr(['switch', 'branchb'], working_dir='heavyco/a')
154
 
        self.assertEqual(branchb_id, checkout.last_revision())
155
 
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
 
156
        # Refresh checkout as 'switch' modified it
 
157
        checkout = checkout.bzrdir.open_workingtree()
 
158
        self.assertEqual(branchb_id, checkout.last_revision())
 
159
        self.assertEqual(tree2.branch.base,
 
160
                         checkout.branch.get_bound_location())
 
161
 
 
162
    def test_switch_finds_relative_unicode_branch(self):
 
163
        """Switch will find 'foo' relative to the branch the checkout is of."""
 
164
        self.requireFeature(UnicodeFilenameFeature)
 
165
        self.build_tree(['repo/'])
 
166
        tree1 = self.make_branch_and_tree('repo/brancha')
 
167
        tree1.commit('foo')
 
168
        tree2 = self.make_branch_and_tree(u'repo/branch\xe9')
 
169
        tree2.pull(tree1.branch)
 
170
        branchb_id = tree2.commit('bar')
 
171
        checkout =  tree1.branch.create_checkout('checkout', lightweight=True)
 
172
        self.run_bzr(['switch', u'branch\xe9'], working_dir='checkout')
 
173
        self.assertEqual(branchb_id, checkout.last_revision())
 
174
        checkout = checkout.bzrdir.open_workingtree()
 
175
        self.assertEqual(tree2.branch.base, checkout.branch.base)
156
176
 
157
177
    def test_switch_finds_relative_unicode_branch(self):
158
178
        """Switch will find 'foo' relative to the branch the checkout is of."""
176
196
        self.assertPathExists('checkout/file-1')
177
197
        self.assertPathDoesNotExist('checkout/file-2')
178
198
 
 
199
    def test_switch_into_colocated(self):
 
200
        # Create a new colocated branch from an existing non-colocated branch.
 
201
        tree = self.make_branch_and_tree('.', format='development-colo')
 
202
        self.build_tree(['file-1', 'file-2'])
 
203
        tree.add('file-1')
 
204
        revid1 = tree.commit('rev1')
 
205
        tree.add('file-2')
 
206
        revid2 = tree.commit('rev2')
 
207
        self.run_bzr(['switch', '-b', 'anotherbranch'])
 
208
        self.assertEqual(
 
209
            set(['', 'anotherbranch']),
 
210
            set(tree.branch.bzrdir.get_branches().keys()))
 
211
 
 
212
    def test_switch_into_unrelated_colocated(self):
 
213
        # Create a new colocated branch from an existing non-colocated branch.
 
214
        tree = self.make_branch_and_tree('.', format='development-colo')
 
215
        self.build_tree(['file-1', 'file-2'])
 
216
        tree.add('file-1')
 
217
        revid1 = tree.commit('rev1')
 
218
        tree.add('file-2')
 
219
        revid2 = tree.commit('rev2')
 
220
        tree.bzrdir.create_branch(name='foo')
 
221
        self.run_bzr_error(['Cannot switch a branch, only a checkout.'],
 
222
            'switch foo')
 
223
        self.run_bzr(['switch', '--force', 'foo'])
 
224
 
179
225
    def test_switch_existing_colocated(self):
180
226
        # Create a branch branch-1 that initially is a checkout of 'foo'
181
227
        # Use switch to change it to 'anotherbranch'
182
228
        repo = self.make_repository('branch-1', format='development-colo')
183
229
        target_branch = repo.bzrdir.create_branch(name='foo')
184
 
        branch.BranchReferenceFormat().initialize(
185
 
            repo.bzrdir, target_branch=target_branch)
 
230
        repo.bzrdir.set_branch_reference(target_branch)
186
231
        tree = repo.bzrdir.create_workingtree()
187
232
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
188
233
        tree.add('file-1')
193
238
        otherbranch.generate_revision_history(revid1)
194
239
        self.run_bzr(['switch', 'anotherbranch'], working_dir='branch-1')
195
240
        tree = WorkingTree.open("branch-1")
196
 
        self.assertEquals(tree.last_revision(), revid1)
197
 
        self.assertEquals(tree.branch.control_url, otherbranch.control_url)
 
241
        self.assertEqual(tree.last_revision(), revid1)
 
242
        self.assertEqual(tree.branch.control_url, otherbranch.control_url)
198
243
 
199
244
    def test_switch_new_colocated(self):
200
245
        # Create a branch branch-1 that initially is a checkout of 'foo'
201
246
        # Use switch to create 'anotherbranch' which derives from that
202
247
        repo = self.make_repository('branch-1', format='development-colo')
203
248
        target_branch = repo.bzrdir.create_branch(name='foo')
204
 
        branch.BranchReferenceFormat().initialize(
205
 
            repo.bzrdir, target_branch=target_branch)
 
249
        repo.bzrdir.set_branch_reference(target_branch)
206
250
        tree = repo.bzrdir.create_workingtree()
207
251
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
208
252
        tree.add('file-1')
209
253
        revid1 = tree.commit('rev1')
210
254
        self.run_bzr(['switch', '-b', 'anotherbranch'], working_dir='branch-1')
211
 
        bzrdir = BzrDir.open("branch-1")
212
 
        self.assertEquals(
 
255
        bzrdir = ControlDir.open("branch-1")
 
256
        self.assertEqual(
213
257
            set([b.name for b in bzrdir.list_branches()]),
214
258
            set(["foo", "anotherbranch"]))
215
 
        self.assertEquals(bzrdir.open_branch().name, "anotherbranch")
216
 
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
259
        self.assertEqual(bzrdir.open_branch().name, "anotherbranch")
 
260
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
217
261
 
218
262
    def test_switch_new_colocated_unicode(self):
219
263
        # Create a branch branch-1 that initially is a checkout of 'foo'
221
265
        self.requireFeature(UnicodeFilenameFeature)
222
266
        repo = self.make_repository('branch-1', format='development-colo')
223
267
        target_branch = repo.bzrdir.create_branch(name='foo')
224
 
        branch.BranchReferenceFormat().initialize(
225
 
            repo.bzrdir, target_branch=target_branch)
 
268
        repo.bzrdir.set_branch_reference(target_branch)
226
269
        tree = repo.bzrdir.create_workingtree()
227
270
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
228
271
        tree.add('file-1')
229
272
        revid1 = tree.commit('rev1')
230
273
        self.run_bzr(['switch', '-b', u'branch\xe9'], working_dir='branch-1')
231
 
        bzrdir = BzrDir.open("branch-1")
232
 
        self.assertEquals(
 
274
        bzrdir = ControlDir.open("branch-1")
 
275
        self.assertEqual(
233
276
            set([b.name for b in bzrdir.list_branches()]),
234
277
            set(["foo", u"branch\xe9"]))
235
 
        self.assertEquals(bzrdir.open_branch().name, u"branch\xe9")
236
 
        self.assertEquals(bzrdir.open_branch().last_revision(), revid1)
 
278
        self.assertEqual(bzrdir.open_branch().name, u"branch\xe9")
 
279
        self.assertEqual(bzrdir.open_branch().last_revision(), revid1)
237
280
 
238
281
    def test_switch_only_revision(self):
239
282
        tree = self._create_sample_tree()
261
304
 
262
305
    def test_switch_lightweight_after_branch_moved_relative(self):
263
306
        self.prepare_lightweight_switch()
264
 
        self.run_bzr('switch --force branch1', working_dir='tree')
 
307
        self.run_bzr('switch --force branch1',
 
308
                     working_dir='tree')
265
309
        branch_location = WorkingTree.open('tree').branch.base
266
310
        self.assertEndsWith(branch_location, 'branch1/')
267
311
 
428
472
        # This test should be cleaner to write, but see bug:
429
473
        #  https://bugs.launchpad.net/bzr/+bug/812295
430
474
        self.assertEqual(1, opened.count('master'))
 
475
 
 
476
 
 
477
class TestSmartServerSwitch(TestCaseWithTransport):
 
478
 
 
479
    def test_switch_lightweight(self):
 
480
        self.setup_smart_server_with_call_log()
 
481
        t = self.make_branch_and_tree('from')
 
482
        for count in range(9):
 
483
            t.commit(message='commit %d' % count)
 
484
        out, err = self.run_bzr(['checkout', '--lightweight', self.get_url('from'),
 
485
            'target'])
 
486
        self.reset_smart_call_log()
 
487
        self.run_bzr(['switch', self.get_url('from')], working_dir='target')
 
488
        # This figure represent the amount of work to perform this use case. It
 
489
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
490
        # being too low. If rpc_count increases, more network roundtrips have
 
491
        # become necessary for this use case. Please do not adjust this number
 
492
        # upwards without agreement from bzr's network support maintainers.
 
493
        self.assertLength(24, self.hpss_calls)
 
494
        self.assertLength(4, self.hpss_connections)
 
495
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
496
 
 
497
 
 
498
class TestSwitchUncommitted(TestCaseWithTransport):
 
499
 
 
500
    def prepare(self):
 
501
        tree = self.make_branch_and_tree('orig')
 
502
        tree.commit('')
 
503
        tree.branch.bzrdir.sprout('new')
 
504
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
505
        self.build_tree(['checkout/a'])
 
506
        self.assertPathExists('checkout/a')
 
507
        checkout.add('a')
 
508
        return checkout
 
509
 
 
510
    def test_store_and_restore_uncommitted(self):
 
511
        checkout = self.prepare()
 
512
        self.run_bzr(['switch', '--store', '-d', 'checkout', 'new'])
 
513
        self.build_tree(['checkout/b'])
 
514
        checkout.add('b')
 
515
        self.assertPathDoesNotExist('checkout/a')
 
516
        self.assertPathExists('checkout/b')
 
517
        self.run_bzr(['switch', '--store', '-d', 'checkout', 'orig'])
 
518
        self.assertPathExists('checkout/a')
 
519
        self.assertPathDoesNotExist('checkout/b')
 
520
 
 
521
    def test_does_not_store(self):
 
522
        self.prepare()
 
523
        self.run_bzr(['switch', '-d', 'checkout', 'new'])
 
524
        self.assertPathExists('checkout/a')
 
525
 
 
526
    def test_does_not_restore_changes(self):
 
527
        self.prepare()
 
528
        self.run_bzr(['switch', '--store', '-d', 'checkout', 'new'])
 
529
        self.assertPathDoesNotExist('checkout/a')
 
530
        self.run_bzr(['switch', '-d', 'checkout', 'orig'])
 
531
        self.assertPathDoesNotExist('checkout/a')