~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Vincent Ladeuil
  • Date: 2007-12-21 12:20:33 UTC
  • mto: (3146.3.1 179368) (3156.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 3158.
  • Revision ID: v.ladeuil+lp@free.fr-20071221122033-42bc21re0zj4kqbg
Merge back test_http_implementations.pc into test_http.py.

* bzrlib/tests/test_http.py: 
Merge test_http_implementations.py now that we have rewritten
load_tests. That should reduce the noise in the final proposed
patch.

* bzrlib/tests/http_server.py:
(TestingHTTPRequestHandler.log_message): Ghaaa, don't over spell-check.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011, 2012 Canonical Ltd
 
1
# Copyright (C) 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib import (
18
18
    branch as _mod_branch,
19
 
    controldir,
20
19
    errors,
21
20
    reconfigure,
22
21
    repository,
23
22
    tests,
24
 
    vf_repository,
25
23
    workingtree,
26
24
    )
27
25
 
45
43
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
46
44
                          'tree')
47
45
 
48
 
    def test_tree_with_pending_merge_to_branch(self):
49
 
        tree = self.make_branch_and_tree('tree')
50
 
        tree.commit('unchanged')
51
 
        other_tree = tree.bzrdir.sprout('other').open_workingtree()
52
 
        other_tree.commit('mergeable commit')
53
 
        tree.merge_from_branch(other_tree.branch)
54
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
55
 
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
56
 
        reconfiguration.apply(force=True)
57
 
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
58
 
                          'tree')
59
 
 
60
46
    def test_branch_to_branch(self):
61
47
        branch = self.make_branch('branch')
62
48
        self.assertRaises(errors.AlreadyBranch,
72
58
        checkout = branch.create_checkout('checkout')
73
59
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
74
60
        reconfiguration.apply()
75
 
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
76
 
        self.assertIs(None, reconfigured.get_bound_location())
 
61
        self.assertIs(None, checkout.branch.get_bound_location())
77
62
 
78
 
    def prepare_lightweight_checkout_to_branch(self):
 
63
    def test_lightweight_checkout_to_branch(self):
79
64
        branch = self.make_branch('branch')
80
65
        checkout = branch.create_checkout('checkout', lightweight=True)
81
66
        checkout.commit('first commit', rev_id='rev1')
82
67
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
83
 
        return reconfiguration, checkout
84
 
 
85
 
    def test_lightweight_checkout_to_branch(self):
86
 
        reconfiguration, checkout = \
87
 
            self.prepare_lightweight_checkout_to_branch()
88
68
        reconfiguration.apply()
89
69
        checkout_branch = checkout.bzrdir.open_branch()
90
70
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
93
73
        repo = checkout.bzrdir.open_repository()
94
74
        repo.get_revision('rev1')
95
75
 
96
 
    def test_lightweight_checkout_to_branch_tags(self):
97
 
        reconfiguration, checkout = \
98
 
            self.prepare_lightweight_checkout_to_branch()
99
 
        checkout.branch.tags.set_tag('foo', 'bar')
100
 
        reconfiguration.apply()
101
 
        checkout_branch = checkout.bzrdir.open_branch()
102
 
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
103
 
 
104
 
    def prepare_lightweight_checkout_to_checkout(self):
 
76
    def test_lightweight_checkout_to_checkout(self):
105
77
        branch = self.make_branch('branch')
106
78
        checkout = branch.create_checkout('checkout', lightweight=True)
107
79
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
108
 
        return reconfiguration, checkout
109
 
 
110
 
    def test_lightweight_checkout_to_checkout(self):
111
 
        reconfiguration, checkout = \
112
 
            self.prepare_lightweight_checkout_to_checkout()
113
80
        reconfiguration.apply()
114
81
        checkout_branch = checkout.bzrdir.open_branch()
115
82
        self.assertIsNot(checkout_branch.get_bound_location(), None)
116
83
 
117
 
    def test_lightweight_checkout_to_checkout_tags(self):
118
 
        reconfiguration, checkout = \
119
 
            self.prepare_lightweight_checkout_to_checkout()
120
 
        checkout.branch.tags.set_tag('foo', 'bar')
121
 
        reconfiguration.apply()
122
 
        checkout_branch = checkout.bzrdir.open_branch()
123
 
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
124
 
 
125
84
    def test_lightweight_conversion_uses_shared_repo(self):
126
85
        parent = self.make_branch('parent')
127
86
        shared_repo = self.make_repository('repo', shared=True)
148
107
        self.assertRaises(errors.NoBindLocation,
149
108
                          reconfiguration._select_bind_location)
150
109
        branch.set_parent('http://parent')
151
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
152
110
        self.assertEqual('http://parent',
153
111
                         reconfiguration._select_bind_location())
154
112
        branch.set_push_location('sftp://push')
155
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
156
113
        self.assertEqual('sftp://push',
157
114
                         reconfiguration._select_bind_location())
158
 
        branch.lock_write()
159
 
        try:
160
 
            branch.set_bound_location('bzr://foo/old-bound')
161
 
            branch.set_bound_location(None)
162
 
        finally:
163
 
            branch.unlock()
164
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
115
        branch.set_bound_location('bzr://foo/old-bound')
 
116
        branch.set_bound_location(None)
165
117
        self.assertEqual('bzr://foo/old-bound',
166
118
                         reconfiguration._select_bind_location())
167
119
        branch.set_bound_location('bzr://foo/cur-bound')
168
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
169
120
        self.assertEqual('bzr://foo/cur-bound',
170
121
                         reconfiguration._select_bind_location())
171
122
        reconfiguration.new_bound_location = 'ftp://user-specified'
189
140
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
190
141
        # setting a parent allows it to become a checkout
191
142
        tree.branch.set_parent(parent.base)
192
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
193
143
        reconfiguration.apply()
194
144
        # supplying a location allows it to become a checkout
195
145
        tree2 = self.make_branch_and_tree('tree2')
208
158
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
209
159
        # setting a parent allows it to become a checkout
210
160
        tree.branch.set_parent(parent.base)
211
 
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
212
 
            tree.bzrdir)
213
161
        reconfiguration.apply()
214
162
        # supplying a location allows it to become a checkout
215
163
        tree2 = self.make_branch_and_tree('tree2')
223
171
        self.assertRaises(errors.AlreadyCheckout,
224
172
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
225
173
 
226
 
    def make_unsynced_checkout(self):
 
174
    def test_checkout_to_lightweight(self):
227
175
        parent = self.make_branch('parent')
228
176
        checkout = parent.create_checkout('checkout')
229
177
        checkout.commit('test', rev_id='new-commit', local=True)
230
178
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
231
179
            checkout.bzrdir)
232
 
        return checkout, parent, reconfiguration
233
 
 
234
 
    def test_unsynced_checkout_to_lightweight(self):
235
 
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
236
 
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
237
 
 
238
 
    def test_synced_checkout_to_lightweight(self):
239
 
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
240
 
        parent.pull(checkout.branch)
241
180
        reconfiguration.apply()
242
181
        wt = checkout.bzrdir.open_workingtree()
243
182
        self.assertTrue(parent.repository.has_same_location(
246
185
        self.assertRaises(errors.NoRepositoryPresent,
247
186
                          checkout.bzrdir.open_repository)
248
187
 
249
 
    def prepare_branch_to_lightweight_checkout(self):
 
188
    def test_branch_to_lightweight_checkout(self):
250
189
        parent = self.make_branch('parent')
251
190
        child = parent.bzrdir.sprout('child').open_workingtree()
252
191
        child.commit('test', rev_id='new-commit')
253
 
        parent.pull(child.branch)
254
192
        child.bzrdir.destroy_workingtree()
255
193
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
256
194
            child.bzrdir)
257
 
        return parent, child, reconfiguration
258
 
 
259
 
    def test_branch_to_lightweight_checkout(self):
260
 
        parent, child, reconfiguration = \
261
 
            self.prepare_branch_to_lightweight_checkout()
262
195
        reconfiguration.apply()
263
 
        self.assertTrue(reconfiguration._destroy_branch)
264
196
        wt = child.bzrdir.open_workingtree()
265
197
        self.assertTrue(parent.repository.has_same_location(
266
198
            wt.branch.repository))
268
200
        self.assertRaises(errors.NoRepositoryPresent,
269
201
                          child.bzrdir.open_repository)
270
202
 
271
 
    def test_branch_to_lightweight_checkout_failure(self):
272
 
        parent, child, reconfiguration = \
273
 
            self.prepare_branch_to_lightweight_checkout()
274
 
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
275
 
        vf_repository.VersionedFileRepository.fetch = None
276
 
        try:
277
 
            self.assertRaises(TypeError, reconfiguration.apply)
278
 
        finally:
279
 
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
280
 
        child = _mod_branch.Branch.open('child')
281
 
        self.assertContainsRe(child.base, 'child/$')
282
 
 
283
 
    def test_branch_to_lightweight_checkout_fetch_tags(self):
284
 
        parent, child, reconfiguration = \
285
 
            self.prepare_branch_to_lightweight_checkout()
286
 
        child.branch.tags.set_tag('foo', 'bar')
287
 
        reconfiguration.apply()
288
 
        child = _mod_branch.Branch.open('child')
289
 
        self.assertEqual('bar', parent.tags.lookup_tag('foo'))
290
 
 
291
203
    def test_lightweight_checkout_to_lightweight_checkout(self):
292
204
        parent = self.make_branch('parent')
293
205
        checkout = parent.create_checkout('checkout', lightweight=True)
322
234
        workingtree.WorkingTree.open('repo')
323
235
        self.assertRaises(errors.NoRepositoryPresent,
324
236
                          repository.Repository.open, 'repo')
325
 
 
326
 
    def test_standalone_to_use_shared(self):
327
 
        self.build_tree(['root/'])
328
 
        tree = self.make_branch_and_tree('root/tree')
329
 
        tree.commit('Hello', rev_id='hello-id')
330
 
        repo = self.make_repository('root', shared=True)
331
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
332
 
        reconfiguration.apply()
333
 
        tree = workingtree.WorkingTree.open('root/tree')
334
 
        self.assertTrue(repo.has_same_location(tree.branch.repository))
335
 
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
336
 
 
337
 
    def add_dead_head(self, tree):
338
 
        revno, revision_id = tree.branch.last_revision_info()
339
 
        tree.commit('Dead head', rev_id='dead-head-id')
340
 
        tree.branch.set_last_revision_info(revno, revision_id)
341
 
        tree.set_last_revision(revision_id)
342
 
 
343
 
    def test_standalone_to_use_shared_preserves_dead_heads(self):
344
 
        self.build_tree(['root/'])
345
 
        tree = self.make_branch_and_tree('root/tree')
346
 
        self.add_dead_head(tree)
347
 
        tree.commit('Hello', rev_id='hello-id')
348
 
        repo = self.make_repository('root', shared=True)
349
 
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
350
 
        reconfiguration.apply()
351
 
        tree = workingtree.WorkingTree.open('root/tree')
352
 
        message = repo.get_revision('dead-head-id').message
353
 
        self.assertEqual('Dead head', message)
354
 
 
355
 
    def make_repository_tree(self):
356
 
        self.build_tree(['root/'])
357
 
        repo = self.make_repository('root', shared=True)
358
 
        tree = self.make_branch_and_tree('root/tree')
359
 
        reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
360
 
        return workingtree.WorkingTree.open('root/tree')
361
 
 
362
 
    def test_use_shared_to_use_shared(self):
363
 
        tree = self.make_repository_tree()
364
 
        self.assertRaises(errors.AlreadyUsingShared,
365
 
                          reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
366
 
 
367
 
    def test_use_shared_to_standalone(self):
368
 
        tree = self.make_repository_tree()
369
 
        tree.commit('Hello', rev_id='hello-id')
370
 
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
371
 
        tree = workingtree.WorkingTree.open('root/tree')
372
 
        repo = tree.branch.repository
373
 
        self.assertEqual(repo.bzrdir.root_transport.base,
374
 
                         tree.bzrdir.root_transport.base)
375
 
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
376
 
 
377
 
    def test_use_shared_to_standalone_preserves_dead_heads(self):
378
 
        tree = self.make_repository_tree()
379
 
        self.add_dead_head(tree)
380
 
        tree.commit('Hello', rev_id='hello-id')
381
 
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
382
 
        tree = workingtree.WorkingTree.open('root/tree')
383
 
        repo = tree.branch.repository
384
 
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
385
 
                          'dead-head-id')
386
 
 
387
 
    def test_standalone_to_standalone(self):
388
 
        tree = self.make_branch_and_tree('tree')
389
 
        self.assertRaises(errors.AlreadyStandalone,
390
 
                          reconfigure.Reconfigure.to_standalone, tree.bzrdir)
391
 
 
392
 
    def make_unsynced_branch_reconfiguration(self):
393
 
        parent = self.make_branch_and_tree('parent')
394
 
        parent.commit('commit 1')
395
 
        child = parent.bzrdir.sprout('child').open_workingtree()
396
 
        child.commit('commit 2')
397
 
        return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
398
 
 
399
 
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
400
 
        reconfiguration = self.make_unsynced_branch_reconfiguration()
401
 
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
402
 
 
403
 
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
404
 
        reconfiguration = self.make_unsynced_branch_reconfiguration()
405
 
        reconfiguration.apply(force=True)
406
 
 
407
 
    def make_repository_with_without_trees(self, with_trees):
408
 
        repo = self.make_repository('repo', shared=True)
409
 
        repo.set_make_working_trees(with_trees)
410
 
        return repo
411
 
 
412
 
    def test_make_with_trees(self):
413
 
        repo = self.make_repository_with_without_trees(False)
414
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
415
 
            repo.bzrdir, True)
416
 
        reconfiguration.apply()
417
 
        self.assertIs(True, repo.make_working_trees())
418
 
 
419
 
    def test_make_without_trees(self):
420
 
        repo = self.make_repository_with_without_trees(True)
421
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
422
 
            repo.bzrdir, False)
423
 
        reconfiguration.apply()
424
 
        self.assertIs(False, repo.make_working_trees())
425
 
 
426
 
    def test_make_with_trees_already_with_trees(self):
427
 
        repo = self.make_repository_with_without_trees(True)
428
 
        e = self.assertRaises(errors.AlreadyWithTrees,
429
 
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
430
 
        self.assertContainsRe(str(e),
431
 
            r"Shared repository '.*' already creates working trees.")
432
 
 
433
 
    def test_make_without_trees_already_no_trees(self):
434
 
        repo = self.make_repository_with_without_trees(False)
435
 
        e = self.assertRaises(errors.AlreadyWithNoTrees,
436
 
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
437
 
        self.assertContainsRe(str(e),
438
 
            r"Shared repository '.*' already doesn't create working trees.")
439
 
 
440
 
    def test_repository_tree_reconfiguration_not_supported(self):
441
 
        tree = self.make_branch_and_tree('tree')
442
 
        e = self.assertRaises(errors.ReconfigurationNotSupported,
443
 
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
444
 
        self.assertContainsRe(str(e),
445
 
            r"Requested reconfiguration of '.*' is not supported.")
446
 
 
447
 
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
448
 
        format = controldir.format_registry.make_bzrdir('1.9')
449
 
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
450
 
        tree = self.make_branch_and_tree('tree', format=format)
451
 
        tree.branch.set_reference_info('file_id', 'path', '../location')
452
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
453
 
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
454
 
        reconfiguration.apply()
455
 
        checkout_branch = checkout.bzrdir.open_branch()
456
 
        self.assertEqual(('path', '../location'),
457
 
                         checkout_branch.get_reference_info('file_id'))