bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
1 |
# Copyright (C) 2005, 2006 Canonical Ltd
|
2 |
#
|
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
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.
|
|
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
7 |
#
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
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.
|
|
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
12 |
#
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
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 |
"""Tests for the Branch facility that are not interface tests.
|
|
18 |
||
|
1534.4.39
by Robert Collins
Basic BzrDir support. |
19 |
For interface tests see tests/branch_implementations/*.py.
|
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
20 |
|
21 |
For concrete class tests see this file, and for meta-branch tests
|
|
22 |
also see this file.
|
|
23 |
"""
|
|
24 |
||
|
1534.4.7
by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same. |
25 |
from StringIO import StringIO |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
26 |
|
|
2230.3.3
by Aaron Bentley
Add more config testing |
27 |
from bzrlib import ( |
28 |
branch as _mod_branch, |
|
|
2230.3.44
by Aaron Bentley
Change asserts to specific errors for left-hand history violations |
29 |
bzrdir, |
30 |
errors, |
|
|
2230.3.3
by Aaron Bentley
Add more config testing |
31 |
urlutils, |
32 |
)
|
|
|
1508.1.25
by Robert Collins
Update per review comments. |
33 |
import bzrlib.branch |
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
34 |
from bzrlib.branch import (BzrBranch5, |
35 |
BzrBranchFormat5) |
|
36 |
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, |
|
37 |
BzrDir, BzrDirFormat) |
|
|
1534.4.7
by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same. |
38 |
from bzrlib.errors import (NotBranchError, |
39 |
UnknownFormatError, |
|
|
2245.1.3
by Robert Collins
Add install_hook to the BranchHooks class as the official means for installing a hook. |
40 |
UnknownHook, |
|
1534.4.7
by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same. |
41 |
UnsupportedFormatError, |
42 |
)
|
|
43 |
||
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
44 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
|
1534.4.4
by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency. |
45 |
from bzrlib.transport import get_transport |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
46 |
|
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
47 |
class TestDefaultFormat(TestCase): |
48 |
||
49 |
def test_get_set_default_format(self): |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
50 |
old_format = bzrlib.branch.BranchFormat.get_default_format() |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
51 |
# default is 5
|
|
1508.1.25
by Robert Collins
Update per review comments. |
52 |
self.assertTrue(isinstance(old_format, bzrlib.branch.BzrBranchFormat5)) |
53 |
bzrlib.branch.BranchFormat.set_default_format(SampleBranchFormat()) |
|
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
54 |
try: |
55 |
# the default branch format is used by the meta dir format
|
|
56 |
# which is not the default bzrdir format at this point
|
|
|
1685.1.42
by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly. |
57 |
dir = BzrDirMetaFormat1().initialize('memory:///') |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
58 |
result = dir.create_branch() |
59 |
self.assertEqual(result, 'A branch') |
|
60 |
finally: |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
61 |
bzrlib.branch.BranchFormat.set_default_format(old_format) |
62 |
self.assertEqual(old_format, bzrlib.branch.BranchFormat.get_default_format()) |
|
63 |
||
64 |
||
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
65 |
class TestBranchFormat5(TestCaseWithTransport): |
66 |
"""Tests specific to branch format 5""" |
|
67 |
||
68 |
def test_branch_format_5_uses_lockdir(self): |
|
69 |
url = self.get_url() |
|
|
1553.5.72
by Martin Pool
Clean up test for Branch5 lockdirs |
70 |
bzrdir = BzrDirMetaFormat1().initialize(url) |
71 |
bzrdir.create_repository() |
|
72 |
branch = bzrdir.create_branch() |
|
73 |
t = self.get_transport() |
|
74 |
self.log("branch instance is %r" % branch) |
|
75 |
self.assert_(isinstance(branch, BzrBranch5)) |
|
76 |
self.assertIsDirectory('.', t) |
|
77 |
self.assertIsDirectory('.bzr/branch', t) |
|
78 |
self.assertIsDirectory('.bzr/branch/lock', t) |
|
|
1553.5.73
by Martin Pool
Additional test that Branch5 uses lockdir properly |
79 |
branch.lock_write() |
|
1658.1.5
by Martin Pool
Release more locks taken during test suite |
80 |
try: |
81 |
self.assertIsDirectory('.bzr/branch/lock/held', t) |
|
82 |
finally: |
|
83 |
branch.unlock() |
|
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
84 |
|
|
2230.3.3
by Aaron Bentley
Add more config testing |
85 |
def test_set_push_location(self): |
86 |
from bzrlib.config import (locations_config_filename, |
|
87 |
ensure_config_dir_exists) |
|
88 |
ensure_config_dir_exists() |
|
89 |
fn = locations_config_filename() |
|
90 |
branch = self.make_branch('.', format='knit') |
|
91 |
branch.set_push_location('foo') |
|
92 |
local_path = urlutils.local_path_from_url(branch.base[:-1]) |
|
93 |
self.assertFileEqual("[%s]\n" |
|
94 |
"push_location = foo\n" |
|
95 |
"push_location:policy = norecurse" % local_path, |
|
96 |
fn) |
|
97 |
||
|
2230.3.12
by Aaron Bentley
Clean up trailing whitespace |
98 |
# TODO RBC 20051029 test getting a push location from a branch in a
|
|
2230.3.3
by Aaron Bentley
Add more config testing |
99 |
# recursive section - that is, it appends the branch name.
|
100 |
||
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
101 |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
102 |
class SampleBranchFormat(bzrlib.branch.BranchFormat): |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
103 |
"""A sample format |
104 |
||
105 |
this format is initializable, unsupported to aid in testing the
|
|
106 |
open and open_downlevel routines.
|
|
107 |
"""
|
|
108 |
||
109 |
def get_format_string(self): |
|
110 |
"""See BzrBranchFormat.get_format_string().""" |
|
111 |
return "Sample branch format." |
|
112 |
||
113 |
def initialize(self, a_bzrdir): |
|
114 |
"""Format 4 branches cannot be created.""" |
|
115 |
t = a_bzrdir.get_branch_transport(self) |
|
|
1955.3.9
by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes |
116 |
t.put_bytes('format', self.get_format_string()) |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
117 |
return 'A branch' |
118 |
||
119 |
def is_supported(self): |
|
120 |
return False |
|
121 |
||
122 |
def open(self, transport, _found=False): |
|
123 |
return "opened branch." |
|
124 |
||
125 |
||
126 |
class TestBzrBranchFormat(TestCaseWithTransport): |
|
127 |
"""Tests for the BzrBranchFormat facility.""" |
|
128 |
||
129 |
def test_find_format(self): |
|
130 |
# is the right format object found for a branch?
|
|
131 |
# create a branch with a few known format objects.
|
|
132 |
# this is not quite the same as
|
|
133 |
self.build_tree(["foo/", "bar/"]) |
|
134 |
def check_format(format, url): |
|
135 |
dir = format._matchingbzrdir.initialize(url) |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
136 |
dir.create_repository() |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
137 |
format.initialize(dir) |
|
1508.1.25
by Robert Collins
Update per review comments. |
138 |
found_format = bzrlib.branch.BranchFormat.find_format(dir) |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
139 |
self.failUnless(isinstance(found_format, format.__class__)) |
|
1508.1.25
by Robert Collins
Update per review comments. |
140 |
check_format(bzrlib.branch.BzrBranchFormat5(), "bar") |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
141 |
|
142 |
def test_find_format_not_branch(self): |
|
143 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
144 |
self.assertRaises(NotBranchError, |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
145 |
bzrlib.branch.BranchFormat.find_format, |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
146 |
dir) |
147 |
||
148 |
def test_find_format_unknown_format(self): |
|
149 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
150 |
SampleBranchFormat().initialize(dir) |
|
151 |
self.assertRaises(UnknownFormatError, |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
152 |
bzrlib.branch.BranchFormat.find_format, |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
153 |
dir) |
154 |
||
155 |
def test_register_unregister_format(self): |
|
156 |
format = SampleBranchFormat() |
|
157 |
# make a control dir
|
|
158 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
159 |
# make a branch
|
|
160 |
format.initialize(dir) |
|
161 |
# register a format for it.
|
|
|
1508.1.25
by Robert Collins
Update per review comments. |
162 |
bzrlib.branch.BranchFormat.register_format(format) |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
163 |
# which branch.Open will refuse (not supported)
|
|
1508.1.25
by Robert Collins
Update per review comments. |
164 |
self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url()) |
|
2230.3.22
by Aaron Bentley
Make test suite use format registry default, not BzrDir default |
165 |
self.make_branch_and_tree('foo') |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
166 |
# but open_downlevel will work
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
167 |
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True)) |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
168 |
# unregister the format
|
|
1508.1.25
by Robert Collins
Update per review comments. |
169 |
bzrlib.branch.BranchFormat.unregister_format(format) |
|
2230.3.22
by Aaron Bentley
Make test suite use format registry default, not BzrDir default |
170 |
self.make_branch_and_tree('bar') |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
171 |
|
|
2230.3.23
by Aaron Bentley
Make checkouts imitate parent format |
172 |
def test_checkout_format(self): |
173 |
branch = self.make_repository('repository', shared=True) |
|
174 |
branch = self.make_branch('repository/branch', |
|
175 |
format='metaweave') |
|
176 |
tree = branch.create_checkout('checkout') |
|
177 |
self.assertIs(tree.branch.__class__, _mod_branch.BzrBranch5) |
|
178 |
||
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
179 |
|
|
2230.3.1
by Aaron Bentley
Get branch6 creation working |
180 |
class TestBranch6(TestCaseWithTransport): |
181 |
||
182 |
def test_creation(self): |
|
183 |
format = BzrDirMetaFormat1() |
|
|
2230.3.55
by Aaron Bentley
Updates from review |
184 |
format.set_branch_format(_mod_branch.BzrBranchFormat6()) |
|
2230.3.1
by Aaron Bentley
Get branch6 creation working |
185 |
branch = self.make_branch('a', format=format) |
186 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
187 |
branch = self.make_branch('b', format='experimental-branch6') |
|
188 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
189 |
branch = _mod_branch.Branch.open('a') |
|
190 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
191 |
||
192 |
def test_layout(self): |
|
193 |
branch = self.make_branch('a', format='experimental-branch6') |
|
194 |
self.failUnlessExists('a/.bzr/branch/last-revision') |
|
195 |
self.failIfExists('a/.bzr/branch/revision-history') |
|
196 |
||
|
2230.3.3
by Aaron Bentley
Add more config testing |
197 |
def test_config(self): |
198 |
"""Ensure that all configuration data is stored in the branch""" |
|
199 |
branch = self.make_branch('a', format='experimental-branch6') |
|
200 |
branch.set_parent('http://bazaar-vcs.org') |
|
201 |
self.failIfExists('a/.bzr/branch/parent') |
|
202 |
self.assertEqual('http://bazaar-vcs.org', branch.get_parent()) |
|
203 |
branch.set_push_location('sftp://bazaar-vcs.org') |
|
204 |
config = branch.get_config()._get_branch_data_config() |
|
|
2230.3.12
by Aaron Bentley
Clean up trailing whitespace |
205 |
self.assertEqual('sftp://bazaar-vcs.org', |
|
2230.3.3
by Aaron Bentley
Add more config testing |
206 |
config.get_user_option('push_location')) |
207 |
branch.set_bound_location('ftp://bazaar-vcs.org') |
|
208 |
self.failIfExists('a/.bzr/branch/bound') |
|
209 |
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location()) |
|
210 |
||
|
2230.3.44
by Aaron Bentley
Change asserts to specific errors for left-hand history violations |
211 |
def test_set_revision_history(self): |
212 |
tree = self.make_branch_and_memory_tree('.', |
|
213 |
format='experimental-branch6') |
|
214 |
tree.lock_write() |
|
215 |
try: |
|
216 |
tree.add('.') |
|
217 |
tree.commit('foo', rev_id='foo') |
|
218 |
tree.commit('bar', rev_id='bar') |
|
219 |
tree.branch.set_revision_history(['foo', 'bar']) |
|
220 |
tree.branch.set_revision_history(['foo']) |
|
221 |
self.assertRaises(errors.NotLefthandHistory, |
|
222 |
tree.branch.set_revision_history, ['bar']) |
|
223 |
finally: |
|
224 |
tree.unlock() |
|
225 |
||
226 |
def test_append_revision(self): |
|
227 |
tree = self.make_branch_and_tree('branch1', |
|
228 |
format='experimental-branch6') |
|
229 |
tree.lock_write() |
|
230 |
try: |
|
231 |
tree.add('.') |
|
232 |
tree.commit('foo', rev_id='foo') |
|
233 |
tree.commit('bar', rev_id='bar') |
|
234 |
tree.commit('baz', rev_id='baz') |
|
235 |
tree.set_last_revision('bar') |
|
|
2230.3.51
by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info |
236 |
tree.branch.set_last_revision_info(2, 'bar') |
|
2230.3.44
by Aaron Bentley
Change asserts to specific errors for left-hand history violations |
237 |
tree.commit('qux', rev_id='qux') |
238 |
tree.add_parent_tree_id('baz') |
|
239 |
tree.commit('qux', rev_id='quxx') |
|
|
2230.3.51
by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info |
240 |
tree.branch.set_last_revision_info(0, 'null:') |
|
2230.3.44
by Aaron Bentley
Change asserts to specific errors for left-hand history violations |
241 |
self.assertRaises(errors.NotLeftParentDescendant, |
242 |
tree.branch.append_revision, 'bar') |
|
243 |
tree.branch.append_revision('foo') |
|
244 |
self.assertRaises(errors.NotLeftParentDescendant, |
|
245 |
tree.branch.append_revision, 'baz') |
|
246 |
tree.branch.append_revision('bar') |
|
247 |
tree.branch.append_revision('baz') |
|
248 |
self.assertRaises(errors.NotLeftParentDescendant, |
|
249 |
tree.branch.append_revision, 'quxx') |
|
250 |
finally: |
|
251 |
tree.unlock() |
|
|
2230.3.51
by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info |
252 |
|
253 |
||
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
254 |
class TestBranchReference(TestCaseWithTransport): |
255 |
"""Tests for the branch reference facility.""" |
|
256 |
||
257 |
def test_create_open_reference(self): |
|
258 |
bzrdirformat = bzrdir.BzrDirMetaFormat1() |
|
259 |
t = get_transport(self.get_url('.')) |
|
260 |
t.mkdir('repo') |
|
261 |
dir = bzrdirformat.initialize(self.get_url('repo')) |
|
262 |
dir.create_repository() |
|
263 |
target_branch = dir.create_branch() |
|
264 |
t.mkdir('branch') |
|
265 |
branch_dir = bzrdirformat.initialize(self.get_url('branch')) |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
266 |
made_branch = bzrlib.branch.BranchReferenceFormat().initialize(branch_dir, target_branch) |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
267 |
self.assertEqual(made_branch.base, target_branch.base) |
268 |
opened_branch = branch_dir.open_branch() |
|
269 |
self.assertEqual(opened_branch.base, target_branch.base) |
|
|
2245.1.1
by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers |
270 |
|
271 |
||
272 |
class TestHooks(TestCase): |
|
273 |
||
|
2245.1.2
by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list. |
274 |
def test_constructor(self): |
275 |
"""Check that creating a BranchHooks instance has the right defaults.""" |
|
276 |
hooks = bzrlib.branch.BranchHooks() |
|
277 |
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks) |
|
|
2246.1.3
by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These |
278 |
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks) |
279 |
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks) |
|
280 |
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks) |
|
281 |
self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks) |
|
|
2245.1.1
by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers |
282 |
|
|
2245.1.2
by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list. |
283 |
def test_installed_hooks_are_BranchHooks(self): |
284 |
"""The installed hooks object should be a BranchHooks.""" |
|
285 |
# the installed hooks are saved in self._preserved_hooks.
|
|
286 |
self.assertIsInstance(self._preserved_hooks, bzrlib.branch.BranchHooks) |
|
|
2245.1.3
by Robert Collins
Add install_hook to the BranchHooks class as the official means for installing a hook. |
287 |
|
288 |
def test_install_hook_raises_unknown_hook(self): |
|
289 |
"""install_hook should raise UnknownHook if a hook is unknown.""" |
|
290 |
hooks = bzrlib.branch.BranchHooks() |
|
291 |
self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None) |
|
292 |
||
293 |
def test_install_hook_appends_known_hook(self): |
|
294 |
"""install_hook should append the callable for known hooks.""" |
|
295 |
hooks = bzrlib.branch.BranchHooks() |
|
296 |
hooks.install_hook('set_rh', None) |
|
297 |
self.assertEqual(hooks['set_rh'], [None]) |