~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_switch.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
25
25
    merge as _mod_merge,
26
26
    switch,
27
27
    tests,
28
 
)
 
28
    )
29
29
 
30
30
 
31
31
class TestSwitch(tests.TestCaseWithTransport):
53
53
            lightweight=self.lightweight)
54
54
        self.build_tree(['checkout/file-3'])
55
55
        checkout.add('file-3')
56
 
        self.failIfExists('checkout/file-1')
57
 
        self.failUnlessExists('checkout/file-2')
 
56
        self.assertPathDoesNotExist('checkout/file-1')
 
57
        self.assertPathExists('checkout/file-2')
58
58
        switch.switch(checkout.bzrdir, to_branch)
59
 
        self.failUnlessExists('checkout/file-1')
60
 
        self.failIfExists('checkout/file-2')
61
 
        self.failUnlessExists('checkout/file-3')
 
59
        self.assertPathExists('checkout/file-1')
 
60
        self.assertPathDoesNotExist('checkout/file-2')
 
61
        self.assertPathExists('checkout/file-3')
62
62
 
63
63
    def test_switch_after_branch_moved(self):
64
64
        """Test switch after the branch is moved."""
84
84
                'Unable to connect to current master branch .*'
85
85
                'To switch anyway, use --force.')
86
86
        switch.switch(checkout.bzrdir, to_branch, force=True)
87
 
        self.failIfExists('checkout/file-1')
88
 
        self.failUnlessExists('checkout/file-2')
89
 
        self.failUnlessExists('checkout/file-3')
 
87
        self.assertPathDoesNotExist('checkout/file-1')
 
88
        self.assertPathExists('checkout/file-2')
 
89
        self.assertPathExists('checkout/file-3')
90
90
 
91
91
    def test_switch_when_pending_merges(self):
92
92
        """Test graceful failure if pending merges are outstanding."""
120
120
        checkout = tree.branch.create_checkout('checkout',
121
121
            lightweight=self.lightweight)
122
122
        switch.switch(checkout.bzrdir, tree.branch, revision_id="rev1")
123
 
        self.failUnlessExists('checkout/file-1')
124
 
        self.failIfExists('checkout/file-2')
 
123
        self.assertPathExists('checkout/file-1')
 
124
        self.assertPathDoesNotExist('checkout/file-2')
125
125
 
126
126
    def test_switch_changing_root_id(self):
127
127
        tree = self._setup_tree()
179
179
        self.assertContainsRe(str(err),
180
180
            'Cannot switch as local commits found in the checkout.')
181
181
        # Check all is ok when force is given
182
 
        self.failIfExists('checkout/file-1')
183
 
        self.failUnlessExists('checkout/file-2')
 
182
        self.assertPathDoesNotExist('checkout/file-1')
 
183
        self.assertPathExists('checkout/file-2')
184
184
        switch.switch(checkout.bzrdir, to_branch, force=True)
185
 
        self.failUnlessExists('checkout/file-1')
186
 
        self.failIfExists('checkout/file-2')
187
 
        self.failIfExists('checkout/file-3')
188
 
        self.failUnlessExists('checkout/file-4')
 
185
        self.assertPathExists('checkout/file-1')
 
186
        self.assertPathDoesNotExist('checkout/file-2')
 
187
        self.assertPathDoesNotExist('checkout/file-3')
 
188
        self.assertPathExists('checkout/file-4')
189
189
        # Check that the checkout is a true mirror of the bound branch
190
190
        self.assertEqual(to_branch.last_revision_info(),
191
191
                         checkout.branch.last_revision_info())