~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009, 2011, 2012 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
72
72
        checkout = branch.create_checkout('checkout')
73
73
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
74
74
        reconfiguration.apply()
75
 
        self.assertIs(None, checkout.branch.get_bound_location())
 
75
        reconfigured = bzrdir.BzrDir.open('checkout').open_branch()
 
76
        self.assertIs(None, reconfigured.get_bound_location())
76
77
 
77
78
    def prepare_lightweight_checkout_to_branch(self):
78
79
        branch = self.make_branch('branch')
146
147
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
147
148
        self.assertRaises(errors.NoBindLocation,
148
149
                          reconfiguration._select_bind_location)
149
 
        branch.set_parent('http://parent')
 
150
        branch.lock_write()
 
151
        try:
 
152
            branch.set_parent('http://parent')
 
153
        finally:
 
154
            branch.unlock()
 
155
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
150
156
        self.assertEqual('http://parent',
151
157
                         reconfiguration._select_bind_location())
152
 
        branch.set_push_location('sftp://push')
 
158
        branch.lock_write()
 
159
        try:
 
160
            branch.set_push_location('sftp://push')
 
161
        finally:
 
162
            branch.unlock()
 
163
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
153
164
        self.assertEqual('sftp://push',
154
165
                         reconfiguration._select_bind_location())
155
 
        branch.set_bound_location('bzr://foo/old-bound')
156
 
        branch.set_bound_location(None)
 
166
        branch.lock_write()
 
167
        try:
 
168
            branch.set_bound_location('bzr://foo/old-bound')
 
169
            branch.set_bound_location(None)
 
170
        finally:
 
171
            branch.unlock()
 
172
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
157
173
        self.assertEqual('bzr://foo/old-bound',
158
174
                         reconfiguration._select_bind_location())
159
 
        branch.set_bound_location('bzr://foo/cur-bound')
 
175
        branch.lock_write()
 
176
        try:
 
177
            branch.set_bound_location('bzr://foo/cur-bound')
 
178
        finally:
 
179
            branch.unlock()
 
180
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
160
181
        self.assertEqual('bzr://foo/cur-bound',
161
182
                         reconfiguration._select_bind_location())
162
183
        reconfiguration.new_bound_location = 'ftp://user-specified'
179
200
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
180
201
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
181
202
        # setting a parent allows it to become a checkout
182
 
        tree.branch.set_parent(parent.base)
 
203
        tree.branch.lock_write()
 
204
        try:
 
205
            tree.branch.set_parent(parent.base)
 
206
        finally:
 
207
            tree.branch.unlock()
 
208
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
183
209
        reconfiguration.apply()
184
210
        # supplying a location allows it to become a checkout
185
211
        tree2 = self.make_branch_and_tree('tree2')
197
223
            tree.bzrdir)
198
224
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
199
225
        # setting a parent allows it to become a checkout
200
 
        tree.branch.set_parent(parent.base)
 
226
        tree.branch.lock_write()
 
227
        try:
 
228
            tree.branch.set_parent(parent.base)
 
229
        finally:
 
230
            tree.branch.unlock()
 
231
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
232
            tree.bzrdir)
201
233
        reconfiguration.apply()
202
234
        # supplying a location allows it to become a checkout
203
235
        tree2 = self.make_branch_and_tree('tree2')