/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib import (
 
18
    branch as _mod_branch,
 
19
    errors,
 
20
    reconfigure,
 
21
    tests,
 
22
    workingtree,
 
23
    )
 
24
 
 
25
 
 
26
class TestReconfigure(tests.TestCaseWithTransport):
 
27
 
 
28
    def test_tree_to_branch(self):
 
29
        tree = self.make_branch_and_tree('tree')
 
30
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
 
31
        reconfiguration.apply()
 
32
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
 
33
                          'tree')
 
34
 
 
35
    def test_modified_tree_to_branch(self):
 
36
        tree = self.make_branch_and_tree('tree')
 
37
        self.build_tree(['tree/file'])
 
38
        tree.add('file')
 
39
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
 
40
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
 
41
        reconfiguration.apply(force=True)
 
42
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
 
43
                          'tree')
 
44
 
 
45
    def test_branch_to_branch(self):
 
46
        branch = self.make_branch('branch')
 
47
        self.assertRaises(errors.AlreadyBranch,
 
48
                          reconfigure.Reconfigure.to_branch, branch.bzrdir)
 
49
 
 
50
    def test_repo_to_branch(self):
 
51
        repo = self.make_repository('repo')
 
52
        self.assertRaises(errors.ReconfigurationNotSupported,
 
53
                          reconfigure.Reconfigure.to_branch, repo.bzrdir)
 
54
 
 
55
    def test_checkout_to_branch(self):
 
56
        branch = self.make_branch('branch')
 
57
        checkout = branch.create_checkout('checkout')
 
58
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
59
        reconfiguration.apply()
 
60
        self.assertIs(None, checkout.branch.get_bound_location())
 
61
 
 
62
    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)
 
67
        reconfiguration.apply()
 
68
        checkout_branch = checkout.bzrdir.open_branch()
 
69
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
 
70
                         checkout.bzrdir.root_transport.base)
 
71
        self.assertEqual('rev1', checkout_branch.last_revision())
 
72
        repo = checkout.bzrdir.open_repository()
 
73
        repo.get_revision('rev1')
 
74
 
 
75
    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)
 
79
        reconfiguration.apply()
 
80
        checkout_branch = checkout.bzrdir.open_branch()
 
81
        self.assertIsNot(checkout_branch.get_bound_location(), None)
 
82
 
 
83
    def test_lightweight_conversion_uses_shared_repo(self):
 
84
        parent = self.make_branch('parent')
 
85
        shared_repo = self.make_repository('repo', shared=True)
 
86
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
 
87
        reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
 
88
        checkout_repo = checkout.bzrdir.open_branch().repository
 
89
        self.assertEqual(shared_repo.bzrdir.root_transport.base,
 
90
                         checkout_repo.bzrdir.root_transport.base)
 
91
 
 
92
    def test_branch_to_tree(self):
 
93
        branch = self.make_branch('branch')
 
94
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
 
95
        reconfiguration.apply()
 
96
        branch.bzrdir.open_workingtree()
 
97
 
 
98
    def test_tree_to_tree(self):
 
99
        tree = self.make_branch_and_tree('tree')
 
100
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
 
101
                          tree.bzrdir)
 
102
 
 
103
    def test_select_bind_location(self):
 
104
        branch = self.make_branch('branch')
 
105
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
106
        self.assertRaises(errors.NoBindLocation,
 
107
                          reconfiguration._select_bind_location)
 
108
        branch.set_parent('http://parent')
 
109
        self.assertEqual('http://parent',
 
110
                         reconfiguration._select_bind_location())
 
111
        branch.set_push_location('sftp://push')
 
112
        self.assertEqual('sftp://push',
 
113
                         reconfiguration._select_bind_location())
 
114
        branch.set_bound_location('bzr:old-bound')
 
115
        branch.set_bound_location(None)
 
116
        self.assertEqual('bzr:old-bound',
 
117
                         reconfiguration._select_bind_location())
 
118
        reconfiguration.new_bound_location = 'ftp://user-specified'
 
119
        self.assertEqual('ftp://user-specified',
 
120
                         reconfiguration._select_bind_location())
 
121
 
 
122
    def test_select_reference_bind_location(self):
 
123
        branch = self.make_branch('branch')
 
124
        checkout = branch.create_checkout('checkout', lightweight=True)
 
125
        reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
 
126
        self.assertEqual(branch.base,
 
127
                         reconfiguration._select_bind_location())
 
128
 
 
129
    def test_tree_to_checkout(self):
 
130
        # A tree with no related branches and no supplied bind location cannot
 
131
        # become a checkout
 
132
        parent = self.make_branch('parent')
 
133
 
 
134
        tree = self.make_branch_and_tree('tree')
 
135
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
 
136
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
137
        # setting a parent allows it to become a checkout
 
138
        tree.branch.set_parent(parent.base)
 
139
        reconfiguration.apply()
 
140
        # supplying a location allows it to become a checkout
 
141
        tree2 = self.make_branch_and_tree('tree2')
 
142
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
 
143
                                                              parent.base)
 
144
        reconfiguration.apply()
 
145
 
 
146
    def test_checkout_to_checkout(self):
 
147
        parent = self.make_branch('parent')
 
148
        checkout = parent.create_checkout('checkout')
 
149
        self.assertRaises(errors.AlreadyCheckout,
 
150
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)