~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-29 08:40:53 UTC
  • mto: (3206.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 3207.
  • Revision ID: v.ladeuil+lp@free.fr-20080129084053-sunwf549ox6zczqr
Fix two more leaked log files.

* bzrlib/tests/test_http.py:
(TestHttpProxyWhiteBox.tearDown): Call the base class tearDown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
    branch as _mod_branch,
19
19
    errors,
20
20
    reconfigure,
 
21
    repository,
21
22
    tests,
22
23
    workingtree,
23
24
    )
49
50
 
50
51
    def test_repo_to_branch(self):
51
52
        repo = self.make_repository('repo')
52
 
        self.assertRaises(errors.ReconfigurationNotSupported,
53
 
                          reconfigure.Reconfigure.to_branch, repo.bzrdir)
 
53
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
 
54
        reconfiguration.apply()
54
55
 
55
56
    def test_checkout_to_branch(self):
56
57
        branch = self.make_branch('branch')
59
60
        reconfiguration.apply()
60
61
        self.assertIs(None, checkout.branch.get_bound_location())
61
62
 
 
63
    def prepare_lightweight_checkout_to_branch(self):
 
64
        branch = self.make_branch('branch')
 
65
        checkout = branch.create_checkout('checkout', lightweight=True)
 
66
        checkout.commit('first commit', rev_id='rev1')
 
67
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
68
        return reconfiguration, checkout
 
69
 
62
70
    def test_lightweight_checkout_to_branch(self):
63
 
        branch = self.make_branch('branch')
64
 
        checkout = branch.create_checkout('checkout', lightweight=True)
65
 
        checkout.commit('first commit', rev_id='rev1')
66
 
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
71
        reconfiguration, checkout = \
 
72
            self.prepare_lightweight_checkout_to_branch()
67
73
        reconfiguration.apply()
68
74
        checkout_branch = checkout.bzrdir.open_branch()
69
75
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
72
78
        repo = checkout.bzrdir.open_repository()
73
79
        repo.get_revision('rev1')
74
80
 
 
81
    def test_lightweight_checkout_to_branch_tags(self):
 
82
        reconfiguration, checkout = \
 
83
            self.prepare_lightweight_checkout_to_branch()
 
84
        checkout.branch.tags.set_tag('foo', 'bar')
 
85
        reconfiguration.apply()
 
86
        checkout_branch = checkout.bzrdir.open_branch()
 
87
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
 
88
 
 
89
    def prepare_lightweight_checkout_to_checkout(self):
 
90
        branch = self.make_branch('branch')
 
91
        checkout = branch.create_checkout('checkout', lightweight=True)
 
92
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
 
93
        return reconfiguration, checkout
 
94
 
75
95
    def test_lightweight_checkout_to_checkout(self):
76
 
        branch = self.make_branch('branch')
77
 
        checkout = branch.create_checkout('checkout', lightweight=True)
78
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
 
96
        reconfiguration, checkout = \
 
97
            self.prepare_lightweight_checkout_to_checkout()
79
98
        reconfiguration.apply()
80
99
        checkout_branch = checkout.bzrdir.open_branch()
81
100
        self.assertIsNot(checkout_branch.get_bound_location(), None)
82
101
 
 
102
    def test_lightweight_checkout_to_checkout_tags(self):
 
103
        reconfiguration, checkout = \
 
104
            self.prepare_lightweight_checkout_to_checkout()
 
105
        checkout.branch.tags.set_tag('foo', 'bar')
 
106
        reconfiguration.apply()
 
107
        checkout_branch = checkout.bzrdir.open_branch()
 
108
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
 
109
 
83
110
    def test_lightweight_conversion_uses_shared_repo(self):
84
111
        parent = self.make_branch('parent')
85
112
        shared_repo = self.make_repository('repo', shared=True)
111
138
        branch.set_push_location('sftp://push')
112
139
        self.assertEqual('sftp://push',
113
140
                         reconfiguration._select_bind_location())
114
 
        branch.set_bound_location('bzr:old-bound')
 
141
        branch.set_bound_location('bzr://foo/old-bound')
115
142
        branch.set_bound_location(None)
116
 
        self.assertEqual('bzr:old-bound',
 
143
        self.assertEqual('bzr://foo/old-bound',
 
144
                         reconfiguration._select_bind_location())
 
145
        branch.set_bound_location('bzr://foo/cur-bound')
 
146
        self.assertEqual('bzr://foo/cur-bound',
117
147
                         reconfiguration._select_bind_location())
118
148
        reconfiguration.new_bound_location = 'ftp://user-specified'
119
149
        self.assertEqual('ftp://user-specified',
143
173
                                                              parent.base)
144
174
        reconfiguration.apply()
145
175
 
 
176
    def test_tree_to_lightweight_checkout(self):
 
177
        # A tree with no related branches and no supplied bind location cannot
 
178
        # become a checkout
 
179
        parent = self.make_branch('parent')
 
180
 
 
181
        tree = self.make_branch_and_tree('tree')
 
182
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
183
            tree.bzrdir)
 
184
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
185
        # setting a parent allows it to become a checkout
 
186
        tree.branch.set_parent(parent.base)
 
187
        reconfiguration.apply()
 
188
        # supplying a location allows it to become a checkout
 
189
        tree2 = self.make_branch_and_tree('tree2')
 
190
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
191
            tree2.bzrdir, parent.base)
 
192
        reconfiguration.apply()
 
193
 
146
194
    def test_checkout_to_checkout(self):
147
195
        parent = self.make_branch('parent')
148
196
        checkout = parent.create_checkout('checkout')
149
197
        self.assertRaises(errors.AlreadyCheckout,
150
198
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
 
199
 
 
200
    def test_checkout_to_lightweight(self):
 
201
        parent = self.make_branch('parent')
 
202
        checkout = parent.create_checkout('checkout')
 
203
        checkout.commit('test', rev_id='new-commit', local=True)
 
204
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
205
            checkout.bzrdir)
 
206
        reconfiguration.apply()
 
207
        wt = checkout.bzrdir.open_workingtree()
 
208
        self.assertTrue(parent.repository.has_same_location(
 
209
            wt.branch.repository))
 
210
        parent.repository.get_revision('new-commit')
 
211
        self.assertRaises(errors.NoRepositoryPresent,
 
212
                          checkout.bzrdir.open_repository)
 
213
 
 
214
    def prepare_branch_to_lightweight_checkout(self):
 
215
        parent = self.make_branch('parent')
 
216
        child = parent.bzrdir.sprout('child').open_workingtree()
 
217
        child.commit('test', rev_id='new-commit')
 
218
        child.bzrdir.destroy_workingtree()
 
219
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
220
            child.bzrdir)
 
221
        return parent, child, reconfiguration
 
222
 
 
223
    def test_branch_to_lightweight_checkout(self):
 
224
        parent, child, reconfiguration = \
 
225
            self.prepare_branch_to_lightweight_checkout()
 
226
        reconfiguration.apply()
 
227
        self.assertTrue(reconfiguration._destroy_branch)
 
228
        wt = child.bzrdir.open_workingtree()
 
229
        self.assertTrue(parent.repository.has_same_location(
 
230
            wt.branch.repository))
 
231
        parent.repository.get_revision('new-commit')
 
232
        self.assertRaises(errors.NoRepositoryPresent,
 
233
                          child.bzrdir.open_repository)
 
234
 
 
235
    def test_branch_to_lightweight_checkout_failure(self):
 
236
        parent, child, reconfiguration = \
 
237
            self.prepare_branch_to_lightweight_checkout()
 
238
        old_Repository_fetch = repository.Repository.fetch
 
239
        repository.Repository.fetch = None
 
240
        try:
 
241
            self.assertRaises(TypeError, reconfiguration.apply)
 
242
        finally:
 
243
            repository.Repository.fetch = old_Repository_fetch
 
244
        child = _mod_branch.Branch.open('child')
 
245
        self.assertContainsRe(child.base, 'child/$')
 
246
 
 
247
    def test_branch_to_lightweight_checkout_fetch_tags(self):
 
248
        parent, child, reconfiguration = \
 
249
            self.prepare_branch_to_lightweight_checkout()
 
250
        child.branch.tags.set_tag('foo', 'bar')
 
251
        reconfiguration.apply()
 
252
        child = _mod_branch.Branch.open('child')
 
253
        self.assertEqual('bar', parent.tags.lookup_tag('foo'))
 
254
 
 
255
    def test_lightweight_checkout_to_lightweight_checkout(self):
 
256
        parent = self.make_branch('parent')
 
257
        checkout = parent.create_checkout('checkout', lightweight=True)
 
258
        self.assertRaises(errors.AlreadyLightweightCheckout,
 
259
                          reconfigure.Reconfigure.to_lightweight_checkout,
 
260
                          checkout.bzrdir)
 
261
 
 
262
    def test_repo_to_tree(self):
 
263
        repo = self.make_repository('repo')
 
264
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
 
265
        reconfiguration.apply()
 
266
        workingtree.WorkingTree.open('repo')
 
267
 
 
268
    def test_shared_repo_to_lightweight_checkout(self):
 
269
        repo = self.make_repository('repo', shared=True)
 
270
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
271
            repo.bzrdir)
 
272
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
273
        branch = self.make_branch('branch')
 
274
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
275
            repo.bzrdir, 'branch')
 
276
        reconfiguration.apply()
 
277
        workingtree.WorkingTree.open('repo')
 
278
        repository.Repository.open('repo')
 
279
 
 
280
    def test_unshared_repo_to_lightweight_checkout(self):
 
281
        repo = self.make_repository('repo', shared=False)
 
282
        branch = self.make_branch('branch')
 
283
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
284
            repo.bzrdir, 'branch')
 
285
        reconfiguration.apply()
 
286
        workingtree.WorkingTree.open('repo')
 
287
        self.assertRaises(errors.NoRepositoryPresent,
 
288
                          repository.Repository.open, 'repo')