bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
1 |
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
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 InterRepository implementastions."""
|
|
18 |
||
|
1711.7.18
by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors |
19 |
import sys |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
20 |
|
|
1534.1.31
by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo. |
21 |
import bzrlib |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
22 |
import bzrlib.bzrdir as bzrdir |
23 |
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock |
|
24 |
import bzrlib.errors as errors |
|
|
3302.5.3
by Vincent Ladeuil
Fix another test bug revealed when run alone. |
25 |
import bzrlib.gpg |
|
1731.1.1
by Aaron Bentley
Make root entry an InventoryDirectory, make EmptyTree really empty |
26 |
from bzrlib.inventory import Inventory |
|
2321.2.3
by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format |
27 |
import bzrlib.repofmt.weaverepo as weaverepo |
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
28 |
import bzrlib.repository as repository |
|
1694.2.6
by Martin Pool
[merge] bzr.dev |
29 |
from bzrlib.revision import NULL_REVISION, Revision |
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
30 |
from bzrlib.symbol_versioning import one_two |
|
2814.1.1
by Robert Collins
* Pushing, pulling and branching branches with subtree references was not |
31 |
from bzrlib.tests import ( |
32 |
TestCase, |
|
33 |
TestCaseWithTransport, |
|
34 |
TestNotApplicable, |
|
35 |
TestSkipped, |
|
36 |
)
|
|
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
37 |
from bzrlib.tests.interrepository_implementations import ( |
38 |
TestCaseWithInterRepository, |
|
39 |
)
|
|
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
40 |
|
41 |
||
|
1711.7.18
by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors |
42 |
def check_old_format_lock_error(repository_format): |
43 |
"""Potentially ignore LockError on old formats. |
|
44 |
||
45 |
On win32, with the old OS locks, we get a failure of double-lock when
|
|
46 |
we open a object in 2 objects and try to lock both.
|
|
47 |
||
48 |
On new formats, LockError would be invalid, but for old formats
|
|
49 |
this was not supported on Win32.
|
|
50 |
"""
|
|
51 |
if sys.platform != 'win32': |
|
52 |
raise
|
|
53 |
||
54 |
description = repository_format.get_format_description() |
|
55 |
if description in ("Repository format 4", |
|
56 |
"Weave repository format 5", |
|
57 |
"Weave repository format 6"): |
|
|
1711.7.30
by John Arbash Meinel
Switch to using TestSkipped for old win32 problems |
58 |
# jam 20060701
|
59 |
# win32 OS locks are not re-entrant. So one process cannot
|
|
60 |
# open the same repository twice and lock them both.
|
|
61 |
raise TestSkipped('%s on win32 cannot open the same' |
|
62 |
' repository twice in different objects'
|
|
63 |
% description) |
|
|
1711.7.18
by John Arbash Meinel
Old repository formats didn't support double locking on win32, don't raise errors |
64 |
raise
|
65 |
||
66 |
||
|
2240.1.3
by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories |
67 |
def check_repo_format_for_funky_id_on_win32(repo): |
|
2321.2.3
by Alexander Belchenko
fix for check_repo_format_for_funky_id_on_win32 after Martin's refactoring of repository format |
68 |
if (isinstance(repo, (weaverepo.AllInOneRepository, |
69 |
weaverepo.WeaveMetaDirRepository)) |
|
70 |
and sys.platform == 'win32'): |
|
|
2240.1.3
by Alexander Belchenko
win32: skip tests that try to use funky chars in fileid in Weave-based repositories |
71 |
raise TestSkipped("funky chars does not permitted" |
72 |
" on this platform in repository"
|
|
73 |
" %s" % repo.__class__.__name__) |
|
74 |
||
75 |
||
|
1534.1.29
by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository. |
76 |
class TestInterRepository(TestCaseWithInterRepository): |
77 |
||
|
1534.1.30
by Robert Collins
Test that we get the right optimiser back in the InterRepository tests. |
78 |
def test_interrepository_get_returns_correct_optimiser(self): |
79 |
# we assume the optimising code paths are triggered
|
|
80 |
# by the type of the repo not the transport - at this point.
|
|
81 |
# we may need to update this test if this changes.
|
|
|
2241.1.4
by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo. |
82 |
#
|
83 |
# XXX: This code tests that we get an InterRepository when we try to
|
|
84 |
# convert between the two repositories that it wants to be tested with
|
|
85 |
# -- but that's not necessarily correct. So for now this is disabled.
|
|
86 |
# mbp 20070206
|
|
87 |
## source_repo = self.make_repository("source")
|
|
88 |
## target_repo = self.make_to_repository("target")
|
|
89 |
## interrepo = repository.InterRepository.get(source_repo, target_repo)
|
|
90 |
## self.assertEqual(self.interrepo_class, interrepo.__class__)
|
|
91 |
pass
|
|
|
1534.1.30
by Robert Collins
Test that we get the right optimiser back in the InterRepository tests. |
92 |
|
|
1843.2.1
by Aaron Bentley
Add failing tests for funky ids |
93 |
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
94 |
|
95 |
class TestCaseWithComplexRepository(TestCaseWithInterRepository): |
|
96 |
||
97 |
def setUp(self): |
|
98 |
super(TestCaseWithComplexRepository, self).setUp() |
|
99 |
tree_a = self.make_branch_and_tree('a') |
|
100 |
self.bzrdir = tree_a.branch.bzrdir |
|
101 |
# add a corrupt inventory 'orphan'
|
|
|
2592.3.91
by Robert Collins
Incrementally closing in on a correct fetch for packs. |
102 |
tree_a.branch.repository.lock_write() |
103 |
tree_a.branch.repository.start_write_group() |
|
104 |
inv_file = tree_a.branch.repository.get_inventory_weave() |
|
|
1563.2.10
by Robert Collins
Change weave store to be a versioned store, using WeaveFiles which maintain integrity without needing explicit 'put' operations. |
105 |
inv_file.add_lines('orphan', [], []) |
|
2592.3.91
by Robert Collins
Incrementally closing in on a correct fetch for packs. |
106 |
tree_a.branch.repository.commit_write_group() |
107 |
tree_a.branch.repository.unlock() |
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
108 |
# add a real revision 'rev1'
|
109 |
tree_a.commit('rev1', rev_id='rev1', allow_pointless=True) |
|
110 |
# add a real revision 'rev2' based on rev1
|
|
111 |
tree_a.commit('rev2', rev_id='rev2', allow_pointless=True) |
|
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
112 |
# and sign 'rev2'
|
|
2592.3.96
by Robert Collins
Merge index improvements (includes bzr.dev). |
113 |
tree_a.branch.repository.lock_write() |
114 |
tree_a.branch.repository.start_write_group() |
|
115 |
tree_a.branch.repository.sign_revision('rev2', bzrlib.gpg.LoopbackGPGStrategy(None)) |
|
116 |
tree_a.branch.repository.commit_write_group() |
|
117 |
tree_a.branch.repository.unlock() |
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
118 |
|
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
119 |
def test_missing_revision_ids_is_deprecated(self): |
120 |
repo_b = self.make_to_repository('rev1_only') |
|
121 |
repo_a = self.bzrdir.open_repository() |
|
122 |
repo_b.fetch(repo_a, 'rev1') |
|
123 |
# check the test will be valid
|
|
124 |
self.assertFalse(repo_b.has_revision('rev2')) |
|
125 |
self.assertEqual(['rev2'], |
|
126 |
self.applyDeprecated(one_two, repo_b.missing_revision_ids, repo_a)) |
|
127 |
inter = repository.InterRepository.get(repo_a, repo_b) |
|
128 |
self.assertEqual(['rev2'], |
|
129 |
self.applyDeprecated(one_two, inter.missing_revision_ids, None, |
|
130 |
True)) |
|
131 |
||
132 |
def test_search_missing_revision_ids(self): |
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
133 |
# revision ids in repository A but not B are returned, fake ones
|
134 |
# are stripped. (fake meaning no revision object, but an inventory
|
|
|
2592.3.146
by Robert Collins
Typo. |
135 |
# as some formats keyed off inventory data in the past.)
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
136 |
# make a repository to compare against that claims to have rev1
|
137 |
repo_b = self.make_to_repository('rev1_only') |
|
138 |
repo_a = self.bzrdir.open_repository() |
|
139 |
repo_b.fetch(repo_a, 'rev1') |
|
140 |
# check the test will be valid
|
|
141 |
self.assertFalse(repo_b.has_revision('rev2')) |
|
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
142 |
result = repo_b.search_missing_revision_ids(repo_a) |
143 |
self.assertEqual(set(['rev2']), result.get_keys()) |
|
144 |
self.assertEqual((set(['rev2']), set(['rev1']), 1), result.get_recipe()) |
|
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
145 |
|
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
146 |
def test_search_missing_revision_ids_absent_requested_raises(self): |
|
3010.1.5
by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts. |
147 |
# Asking for missing revisions with a tip that is itself absent in the
|
148 |
# source raises NoSuchRevision.
|
|
149 |
repo_b = self.make_to_repository('target') |
|
150 |
repo_a = self.bzrdir.open_repository() |
|
151 |
# No pizza revisions anywhere
|
|
152 |
self.assertFalse(repo_a.has_revision('pizza')) |
|
153 |
self.assertFalse(repo_b.has_revision('pizza')) |
|
154 |
# Asking specifically for an absent revision errors.
|
|
|
3380.1.4
by Aaron Bentley
Split interrepository fetch tests into their own file |
155 |
self.assertRaises(errors.NoSuchRevision, |
156 |
repo_b.search_missing_revision_ids, repo_a, revision_id='pizza', |
|
157 |
find_ghosts=True) |
|
158 |
self.assertRaises(errors.NoSuchRevision, |
|
159 |
repo_b.search_missing_revision_ids, repo_a, revision_id='pizza', |
|
160 |
find_ghosts=False) |
|
|
3010.1.5
by Robert Collins
Test that missing_revision_ids handles the case of the source not having the requested revision correctly with and without find_ghosts. |
161 |
|
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
162 |
def test_search_missing_revision_ids_revision_limited(self): |
|
1534.1.34
by Robert Collins
Move missing_revision_ids from Repository to InterRepository, and eliminate the now unused Repository._compatible_formats method. |
163 |
# revision ids in repository A that are not referenced by the
|
164 |
# requested revision are not returned.
|
|
165 |
# make a repository to compare against that is empty
|
|
166 |
repo_b = self.make_to_repository('empty') |
|
167 |
repo_a = self.bzrdir.open_repository() |
|
|
3184.1.8
by Robert Collins
* ``InterRepository.missing_revision_ids`` is now deprecated in favour of |
168 |
result = repo_b.search_missing_revision_ids(repo_a, revision_id='rev1') |
169 |
self.assertEqual(set(['rev1']), result.get_keys()) |
|
170 |
self.assertEqual((set(['rev1']), set([NULL_REVISION]), 1), |
|
171 |
result.get_recipe()) |
|
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
172 |
|
|
2592.3.91
by Robert Collins
Incrementally closing in on a correct fetch for packs. |
173 |
def test_fetch_fetches_signatures_too(self): |
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
174 |
from_repo = self.bzrdir.open_repository() |
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
175 |
from_signature = from_repo.get_signature_text('rev2') |
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
176 |
to_repo = self.make_to_repository('target') |
177 |
to_repo.fetch(from_repo) |
|
|
1563.2.31
by Robert Collins
Convert Knit repositories to use knits. |
178 |
to_signature = to_repo.get_signature_text('rev2') |
|
1556.1.4
by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same. |
179 |
self.assertEqual(from_signature, to_signature) |
180 |
||
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
181 |
|
182 |
class TestCaseWithGhosts(TestCaseWithInterRepository): |
|
183 |
||
|
2949.1.2
by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph. |
184 |
def test_fetch_all_fixes_up_ghost(self): |
185 |
# we want two repositories at this point:
|
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
186 |
# one with a revision that is a ghost in the other
|
187 |
# repository.
|
|
|
2949.1.2
by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph. |
188 |
# 'ghost' is present in has_ghost, 'ghost' is absent in 'missing_ghost'.
|
189 |
# 'references' is present in both repositories, and 'tip' is present
|
|
190 |
# just in has_ghost.
|
|
191 |
# has_ghost missing_ghost
|
|
192 |
#------------------------------
|
|
193 |
# 'ghost' -
|
|
194 |
# 'references' 'references'
|
|
195 |
# 'tip' -
|
|
196 |
# In this test we fetch 'tip' which should not fetch 'ghost'
|
|
197 |
has_ghost = self.make_repository('has_ghost') |
|
198 |
missing_ghost = self.make_repository('missing_ghost') |
|
199 |
if [True, True] != [repo._format.supports_ghosts for repo in |
|
200 |
(has_ghost, missing_ghost)]: |
|
201 |
raise TestNotApplicable("Need ghost support.") |
|
202 |
||
203 |
def add_commit(repo, revision_id, parent_ids): |
|
204 |
repo.lock_write() |
|
205 |
repo.start_write_group() |
|
206 |
inv = Inventory(revision_id=revision_id) |
|
207 |
inv.root.revision = revision_id |
|
208 |
root_id = inv.root.file_id |
|
209 |
sha1 = repo.add_inventory(revision_id, inv, parent_ids) |
|
210 |
vf = repo.weave_store.get_weave_or_empty(root_id, |
|
211 |
repo.get_transaction()) |
|
212 |
vf.add_lines(revision_id, [], []) |
|
213 |
rev = bzrlib.revision.Revision(timestamp=0, |
|
214 |
timezone=None, |
|
215 |
committer="Foo Bar <foo@example.com>", |
|
216 |
message="Message", |
|
217 |
inventory_sha1=sha1, |
|
218 |
revision_id=revision_id) |
|
219 |
rev.parent_ids = parent_ids |
|
220 |
repo.add_revision(revision_id, rev) |
|
221 |
repo.commit_write_group() |
|
222 |
repo.unlock() |
|
223 |
add_commit(has_ghost, 'ghost', []) |
|
224 |
add_commit(has_ghost, 'references', ['ghost']) |
|
225 |
add_commit(missing_ghost, 'references', ['ghost']) |
|
226 |
add_commit(has_ghost, 'tip', ['references']) |
|
227 |
missing_ghost.fetch(has_ghost, 'tip', find_ghosts=True) |
|
228 |
# missing ghost now has tip and ghost.
|
|
229 |
rev = missing_ghost.get_revision('tip') |
|
230 |
inv = missing_ghost.get_inventory('tip') |
|
231 |
rev = missing_ghost.get_revision('ghost') |
|
232 |
inv = missing_ghost.get_inventory('ghost') |
|
|
1570.1.14
by Robert Collins
Enforce repository consistency during 'fetch' operations. |
233 |
# rev must not be corrupt now
|
|
2949.1.2
by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph. |
234 |
self.assertEqual([None, 'ghost', 'references', 'tip'], |
235 |
missing_ghost.get_ancestry('tip')) |