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, |
|
29 |
urlutils, |
|
30 |
)
|
|
|
1508.1.25
by Robert Collins
Update per review comments. |
31 |
import bzrlib.branch |
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
32 |
from bzrlib.branch import (BzrBranch5, |
33 |
BzrBranchFormat5) |
|
|
1534.4.41
by Robert Collins
Branch now uses BzrDir reasonably sanely. |
34 |
import bzrlib.bzrdir as bzrdir |
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
35 |
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, |
36 |
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. |
37 |
from bzrlib.errors import (NotBranchError, |
38 |
UnknownFormatError, |
|
39 |
UnsupportedFormatError, |
|
40 |
)
|
|
41 |
||
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
42 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
|
1534.4.4
by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency. |
43 |
from bzrlib.transport import get_transport |
|
1534.4.3
by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats. |
44 |
|
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
45 |
class TestDefaultFormat(TestCase): |
46 |
||
47 |
def test_get_set_default_format(self): |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
48 |
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. |
49 |
# default is 5
|
|
1508.1.25
by Robert Collins
Update per review comments. |
50 |
self.assertTrue(isinstance(old_format, bzrlib.branch.BzrBranchFormat5)) |
51 |
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. |
52 |
try: |
53 |
# the default branch format is used by the meta dir format
|
|
54 |
# 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. |
55 |
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. |
56 |
result = dir.create_branch() |
57 |
self.assertEqual(result, 'A branch') |
|
58 |
finally: |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
59 |
bzrlib.branch.BranchFormat.set_default_format(old_format) |
60 |
self.assertEqual(old_format, bzrlib.branch.BranchFormat.get_default_format()) |
|
61 |
||
62 |
||
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
63 |
class TestBranchFormat5(TestCaseWithTransport): |
64 |
"""Tests specific to branch format 5""" |
|
65 |
||
66 |
def test_branch_format_5_uses_lockdir(self): |
|
67 |
url = self.get_url() |
|
|
1553.5.72
by Martin Pool
Clean up test for Branch5 lockdirs |
68 |
bzrdir = BzrDirMetaFormat1().initialize(url) |
69 |
bzrdir.create_repository() |
|
70 |
branch = bzrdir.create_branch() |
|
71 |
t = self.get_transport() |
|
72 |
self.log("branch instance is %r" % branch) |
|
73 |
self.assert_(isinstance(branch, BzrBranch5)) |
|
74 |
self.assertIsDirectory('.', t) |
|
75 |
self.assertIsDirectory('.bzr/branch', t) |
|
76 |
self.assertIsDirectory('.bzr/branch/lock', t) |
|
|
1553.5.73
by Martin Pool
Additional test that Branch5 uses lockdir properly |
77 |
branch.lock_write() |
|
1658.1.5
by Martin Pool
Release more locks taken during test suite |
78 |
try: |
79 |
self.assertIsDirectory('.bzr/branch/lock/held', t) |
|
80 |
finally: |
|
81 |
branch.unlock() |
|
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
82 |
|
|
2230.3.3
by Aaron Bentley
Add more config testing |
83 |
def test_set_push_location(self): |
84 |
from bzrlib.config import (locations_config_filename, |
|
85 |
ensure_config_dir_exists) |
|
86 |
ensure_config_dir_exists() |
|
87 |
fn = locations_config_filename() |
|
88 |
branch = self.make_branch('.', format='knit') |
|
89 |
branch.set_push_location('foo') |
|
90 |
local_path = urlutils.local_path_from_url(branch.base[:-1]) |
|
91 |
self.assertFileEqual("[%s]\n" |
|
92 |
"push_location = foo\n" |
|
93 |
"push_location:policy = norecurse" % local_path, |
|
94 |
fn) |
|
95 |
||
96 |
# TODO RBC 20051029 test getting a push location from a branch in a
|
|
97 |
# recursive section - that is, it appends the branch name.
|
|
98 |
||
|
1553.5.71
by Martin Pool
Change branch format 5 to use LockDirs, not transport locks |
99 |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
100 |
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. |
101 |
"""A sample format |
102 |
||
103 |
this format is initializable, unsupported to aid in testing the
|
|
104 |
open and open_downlevel routines.
|
|
105 |
"""
|
|
106 |
||
107 |
def get_format_string(self): |
|
108 |
"""See BzrBranchFormat.get_format_string().""" |
|
109 |
return "Sample branch format." |
|
110 |
||
111 |
def initialize(self, a_bzrdir): |
|
112 |
"""Format 4 branches cannot be created.""" |
|
113 |
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 |
114 |
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. |
115 |
return 'A branch' |
116 |
||
117 |
def is_supported(self): |
|
118 |
return False |
|
119 |
||
120 |
def open(self, transport, _found=False): |
|
121 |
return "opened branch." |
|
122 |
||
123 |
||
124 |
class TestBzrBranchFormat(TestCaseWithTransport): |
|
125 |
"""Tests for the BzrBranchFormat facility.""" |
|
126 |
||
127 |
def test_find_format(self): |
|
128 |
# is the right format object found for a branch?
|
|
129 |
# create a branch with a few known format objects.
|
|
130 |
# this is not quite the same as
|
|
131 |
self.build_tree(["foo/", "bar/"]) |
|
132 |
def check_format(format, url): |
|
133 |
dir = format._matchingbzrdir.initialize(url) |
|
|
1534.4.47
by Robert Collins
Split out repository into .bzr/repository |
134 |
dir.create_repository() |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
135 |
format.initialize(dir) |
|
1508.1.25
by Robert Collins
Update per review comments. |
136 |
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. |
137 |
self.failUnless(isinstance(found_format, format.__class__)) |
|
1508.1.25
by Robert Collins
Update per review comments. |
138 |
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. |
139 |
|
140 |
def test_find_format_not_branch(self): |
|
141 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
142 |
self.assertRaises(NotBranchError, |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
143 |
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. |
144 |
dir) |
145 |
||
146 |
def test_find_format_unknown_format(self): |
|
147 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
148 |
SampleBranchFormat().initialize(dir) |
|
149 |
self.assertRaises(UnknownFormatError, |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
150 |
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. |
151 |
dir) |
152 |
||
153 |
def test_register_unregister_format(self): |
|
154 |
format = SampleBranchFormat() |
|
155 |
# make a control dir
|
|
156 |
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url()) |
|
157 |
# make a branch
|
|
158 |
format.initialize(dir) |
|
159 |
# register a format for it.
|
|
|
1508.1.25
by Robert Collins
Update per review comments. |
160 |
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. |
161 |
# which branch.Open will refuse (not supported)
|
|
1508.1.25
by Robert Collins
Update per review comments. |
162 |
self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url()) |
|
1534.4.44
by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory. |
163 |
# 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. |
164 |
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. |
165 |
# unregister the format
|
|
1508.1.25
by Robert Collins
Update per review comments. |
166 |
bzrlib.branch.BranchFormat.unregister_format(format) |
|
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 |
|
168 |
||
|
2230.3.1
by Aaron Bentley
Get branch6 creation working |
169 |
class TestBranch6(TestCaseWithTransport): |
170 |
||
171 |
def test_creation(self): |
|
172 |
format = BzrDirMetaFormat1() |
|
173 |
format.branch_format = _mod_branch.BzrBranchFormat6() |
|
174 |
branch = self.make_branch('a', format=format) |
|
175 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
176 |
branch = self.make_branch('b', format='experimental-branch6') |
|
177 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
178 |
branch = _mod_branch.Branch.open('a') |
|
179 |
self.assertIsInstance(branch, _mod_branch.BzrBranch6) |
|
180 |
||
181 |
def test_layout(self): |
|
182 |
branch = self.make_branch('a', format='experimental-branch6') |
|
183 |
self.failUnlessExists('a/.bzr/branch/last-revision') |
|
184 |
self.failIfExists('a/.bzr/branch/revision-history') |
|
185 |
||
|
2230.3.3
by Aaron Bentley
Add more config testing |
186 |
def test_config(self): |
187 |
"""Ensure that all configuration data is stored in the branch""" |
|
188 |
branch = self.make_branch('a', format='experimental-branch6') |
|
189 |
branch.set_parent('http://bazaar-vcs.org') |
|
190 |
self.failIfExists('a/.bzr/branch/parent') |
|
191 |
self.assertEqual('http://bazaar-vcs.org', branch.get_parent()) |
|
192 |
branch.set_push_location('sftp://bazaar-vcs.org') |
|
193 |
config = branch.get_config()._get_branch_data_config() |
|
194 |
self.assertEqual('sftp://bazaar-vcs.org', |
|
195 |
config.get_user_option('push_location')) |
|
196 |
branch.set_bound_location('ftp://bazaar-vcs.org') |
|
197 |
self.failIfExists('a/.bzr/branch/bound') |
|
198 |
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location()) |
|
199 |
||
|
2230.3.1
by Aaron Bentley
Get branch6 creation working |
200 |
|
|
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. |
201 |
class TestBranchReference(TestCaseWithTransport): |
202 |
"""Tests for the branch reference facility.""" |
|
203 |
||
204 |
def test_create_open_reference(self): |
|
205 |
bzrdirformat = bzrdir.BzrDirMetaFormat1() |
|
206 |
t = get_transport(self.get_url('.')) |
|
207 |
t.mkdir('repo') |
|
208 |
dir = bzrdirformat.initialize(self.get_url('repo')) |
|
209 |
dir.create_repository() |
|
210 |
target_branch = dir.create_branch() |
|
211 |
t.mkdir('branch') |
|
212 |
branch_dir = bzrdirformat.initialize(self.get_url('branch')) |
|
|
1508.1.25
by Robert Collins
Update per review comments. |
213 |
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. |
214 |
self.assertEqual(made_branch.base, target_branch.base) |
215 |
opened_branch = branch_dir.open_branch() |
|
216 |
self.assertEqual(opened_branch.base, target_branch.base) |