~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: 2010-01-25 15:55:48 UTC
  • mto: (4985.1.4 add-attr-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4988.
  • Revision ID: v.ladeuil+lp@free.fr-20100125155548-0l352pujvt5bzl5e
Deploy addAttrCleanup on the whole test suite.

Several use case worth mentioning:

- setting a module or any other object attribute is the majority
by far. In some cases the setting itself is deferred but most of
the time we want to set at the same time we add the cleanup.

- there multiple occurrences of protecting hooks or ui factory
which are now useless (the test framework takes care of that now),

- there was some lambda uses that can now be avoided.

That first cleanup already simplifies things a lot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib.workingtree import WorkingTree
24
24
from bzrlib.tests.blackbox import ExternalBase
 
25
from bzrlib.directory_service import directories
25
26
 
26
27
 
27
28
class TestSwitch(ExternalBase):
28
29
 
 
30
    def _create_sample_tree(self):
 
31
        tree = self.make_branch_and_tree('branch-1')
 
32
        self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
 
33
        tree.add('file-1')
 
34
        tree.commit('rev1')
 
35
        tree.add('file-2')
 
36
        tree.commit('rev2')
 
37
        return tree
 
38
 
29
39
    def test_switch_up_to_date_light_checkout(self):
30
40
        self.make_branch_and_tree('branch')
31
41
        self.run_bzr('branch branch branch2')
134
144
        self.assertEqual(branchb_id, checkout.last_revision())
135
145
        self.assertEqual(tree2.branch.base, checkout.branch.get_bound_location())
136
146
 
 
147
    def test_switch_revision(self):
 
148
        tree = self._create_sample_tree()
 
149
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
150
        self.run_bzr(['switch', 'branch-1', '-r1'], working_dir='checkout')
 
151
        self.failUnlessExists('checkout/file-1')
 
152
        self.failIfExists('checkout/file-2')
 
153
 
 
154
    def test_switch_only_revision(self):
 
155
        tree = self._create_sample_tree()
 
156
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
157
        self.failUnlessExists('checkout/file-1')
 
158
        self.failUnlessExists('checkout/file-2')
 
159
        self.run_bzr(['switch', '-r1'], working_dir='checkout')
 
160
        self.failUnlessExists('checkout/file-1')
 
161
        self.failIfExists('checkout/file-2')
 
162
        # Check that we don't accept a range
 
163
        self.run_bzr_error(
 
164
            ['bzr switch --revision takes exactly one revision identifier'],
 
165
            ['switch', '-r0..2'], working_dir='checkout')
 
166
 
137
167
    def prepare_lightweight_switch(self):
138
168
        branch = self.make_branch('branch')
139
169
        branch.create_checkout('tree', lightweight=True)
183
213
        # The new branch should have been created at the same level as
184
214
        # 'branch', because we did not have a '/' segment
185
215
        self.assertEqual(branch.base[:-1] + '2/', tree.branch.base)
 
216
 
 
217
    def test_create_branch_directory_services(self):
 
218
        branch = self.make_branch('branch')
 
219
        tree = branch.create_checkout('tree', lightweight=True)
 
220
        class FooLookup(object):
 
221
            def look_up(self, name, url):
 
222
                return 'foo-'+name
 
223
        directories.register('foo:', FooLookup, 'Create branches named foo-')
 
224
        self.addCleanup(directories.remove, 'foo:')
 
225
        self.run_bzr('switch -b foo:branch2', working_dir='tree')
 
226
        tree = WorkingTree.open('tree')
 
227
        self.assertEndsWith(tree.branch.base, 'foo-branch2/')