bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
1 |
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
|
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 |
"""Tests for bzr-git's object store."""
|
|
18 |
||
19 |
from dulwich.objects import ( |
|
20 |
Blob, |
|
21 |
)
|
|
22 |
||
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
23 |
from bzrlib.branchbuilder import ( |
24 |
BranchBuilder, |
|
25 |
)
|
|
26 |
from bzrlib.errors import ( |
|
27 |
NoSuchRevision, |
|
28 |
)
|
|
|
0.200.899
by Jelmer Vernooij
Add tests for find_missing_bzr_revids. |
29 |
from bzrlib.graph import ( |
30 |
DictParentsProvider, |
|
|
0.200.1059
by Jelmer Vernooij
Fix graph tests. |
31 |
Graph, |
|
0.200.899
by Jelmer Vernooij
Add tests for find_missing_bzr_revids. |
32 |
)
|
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
33 |
from bzrlib.tests import ( |
34 |
TestCase, |
|
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
35 |
TestCaseWithTransport, |
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
36 |
)
|
37 |
||
|
0.200.1016
by Jelmer Vernooij
add basic test for tree_to_objects. |
38 |
from bzrlib.plugins.git.cache import ( |
39 |
DictGitShaMap, |
|
40 |
)
|
|
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
41 |
from bzrlib.plugins.git.object_store import ( |
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
42 |
BazaarObjectStore, |
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
43 |
LRUTreeCache, |
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
44 |
_check_expected_sha, |
|
0.200.899
by Jelmer Vernooij
Add tests for find_missing_bzr_revids. |
45 |
_find_missing_bzr_revids, |
|
0.200.1016
by Jelmer Vernooij
add basic test for tree_to_objects. |
46 |
_tree_to_objects, |
|
0.200.799
by Jelmer Vernooij
Add trivial object store tests. |
47 |
)
|
48 |
||
49 |
||
50 |
class ExpectedShaTests(TestCase): |
|
51 |
||
52 |
def setUp(self): |
|
53 |
super(ExpectedShaTests, self).setUp() |
|
54 |
self.obj = Blob() |
|
55 |
self.obj.data = "foo" |
|
56 |
||
57 |
def test_none(self): |
|
58 |
_check_expected_sha(None, self.obj) |
|
59 |
||
60 |
def test_hex(self): |
|
61 |
_check_expected_sha(self.obj.sha().hexdigest(), self.obj) |
|
62 |
self.assertRaises(AssertionError, _check_expected_sha, |
|
63 |
"0" * 40, self.obj) |
|
64 |
||
65 |
def test_binary(self): |
|
66 |
_check_expected_sha(self.obj.sha().digest(), self.obj) |
|
67 |
self.assertRaises(AssertionError, _check_expected_sha, |
|
68 |
"x" * 20, self.obj) |
|
|
0.200.899
by Jelmer Vernooij
Add tests for find_missing_bzr_revids. |
69 |
|
70 |
||
71 |
class FindMissingBzrRevidsTests(TestCase): |
|
72 |
||
73 |
def _find_missing(self, ancestry, want, have): |
|
74 |
return _find_missing_bzr_revids( |
|
|
0.200.1059
by Jelmer Vernooij
Fix graph tests. |
75 |
Graph(DictParentsProvider(ancestry)), |
|
0.200.899
by Jelmer Vernooij
Add tests for find_missing_bzr_revids. |
76 |
set(want), set(have)) |
77 |
||
78 |
def test_simple(self): |
|
79 |
self.assertEquals(set(), self._find_missing({}, [], [])) |
|
80 |
||
81 |
def test_up_to_date(self): |
|
82 |
self.assertEquals(set(), |
|
83 |
self._find_missing({"a": ["b"]}, ["a"], ["a"])) |
|
84 |
||
85 |
def test_one_missing(self): |
|
86 |
self.assertEquals(set(["a"]), |
|
87 |
self._find_missing({"a": ["b"]}, ["a"], ["b"])) |
|
|
0.200.905
by Jelmer Vernooij
More find missing revision tests. |
88 |
|
89 |
def test_two_missing(self): |
|
90 |
self.assertEquals(set(["a", "b"]), |
|
91 |
self._find_missing({"a": ["b"], "b": ["c"]}, ["a"], ["c"])) |
|
92 |
||
93 |
def test_two_missing_history(self): |
|
94 |
self.assertEquals(set(["a", "b"]), |
|
95 |
self._find_missing({"a": ["b"], "b": ["c"], "c": ["d"]}, |
|
96 |
["a"], ["c"])) |
|
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
97 |
|
98 |
||
99 |
class LRUTreeCacheTests(TestCaseWithTransport): |
|
100 |
||
101 |
def setUp(self): |
|
102 |
super(LRUTreeCacheTests, self).setUp() |
|
103 |
self.branch = self.make_branch(".") |
|
104 |
self.branch.lock_write() |
|
105 |
self.addCleanup(self.branch.unlock) |
|
106 |
self.cache = LRUTreeCache(self.branch.repository) |
|
107 |
||
108 |
def test_get_not_present(self): |
|
|
0.200.965
by Jelmer Vernooij
Formatting fixes. |
109 |
self.assertRaises(NoSuchRevision, self.cache.revision_tree, |
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
110 |
"unknown") |
111 |
||
112 |
def test_revision_trees(self): |
|
|
0.200.965
by Jelmer Vernooij
Formatting fixes. |
113 |
self.assertRaises(NoSuchRevision, self.cache.revision_trees, |
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
114 |
["unknown", "la"]) |
115 |
||
116 |
def test_iter_revision_trees(self): |
|
|
0.200.965
by Jelmer Vernooij
Formatting fixes. |
117 |
self.assertRaises(NoSuchRevision, self.cache.iter_revision_trees, |
|
0.200.963
by Jelmer Vernooij
Add some tests for LRUTreeCache. |
118 |
["unknown", "la"]) |
119 |
||
120 |
def test_get(self): |
|
121 |
bb = BranchBuilder(branch=self.branch) |
|
122 |
bb.start_series() |
|
123 |
bb.build_snapshot('BASE-id', None, |
|
124 |
[('add', ('', None, 'directory', None)), |
|
125 |
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')), |
|
126 |
])
|
|
127 |
bb.finish_series() |
|
128 |
tree = self.cache.revision_tree("BASE-id") |
|
129 |
self.assertEquals("BASE-id", tree.get_revision_id()) |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
130 |
|
131 |
||
132 |
class BazaarObjectStoreTests(TestCaseWithTransport): |
|
133 |
||
134 |
def setUp(self): |
|
135 |
super(BazaarObjectStoreTests, self).setUp() |
|
136 |
self.branch = self.make_branch(".") |
|
137 |
self.branch.lock_write() |
|
138 |
self.addCleanup(self.branch.unlock) |
|
139 |
self.store = BazaarObjectStore(self.branch.repository) |
|
140 |
||
141 |
def test_get_blob(self): |
|
142 |
b = Blob() |
|
143 |
b.data = 'a\nb\nc\nd\ne\n' |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
144 |
self.store.lock_read() |
145 |
self.addCleanup(self.store.unlock) |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
146 |
self.assertRaises(KeyError, self.store.__getitem__, b.id) |
147 |
bb = BranchBuilder(branch=self.branch) |
|
148 |
bb.start_series() |
|
149 |
bb.build_snapshot('BASE-id', None, |
|
150 |
[('add', ('', None, 'directory', None)), |
|
151 |
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')), |
|
152 |
])
|
|
153 |
bb.finish_series() |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
154 |
# read locks cache
|
155 |
self.assertRaises(KeyError, self.store.__getitem__, b.id) |
|
156 |
self.store.unlock() |
|
157 |
self.store.lock_read() |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
158 |
self.assertEquals(b, self.store[b.id]) |
159 |
||
160 |
def test_get_raw(self): |
|
161 |
b = Blob() |
|
162 |
b.data = 'a\nb\nc\nd\ne\n' |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
163 |
self.store.lock_read() |
164 |
self.addCleanup(self.store.unlock) |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
165 |
self.assertRaises(KeyError, self.store.get_raw, b.id) |
166 |
bb = BranchBuilder(branch=self.branch) |
|
167 |
bb.start_series() |
|
168 |
bb.build_snapshot('BASE-id', None, |
|
169 |
[('add', ('', None, 'directory', None)), |
|
170 |
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')), |
|
171 |
])
|
|
172 |
bb.finish_series() |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
173 |
# read locks cache
|
174 |
self.assertRaises(KeyError, self.store.get_raw, b.id) |
|
175 |
self.store.unlock() |
|
176 |
self.store.lock_read() |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
177 |
self.assertEquals(b.as_raw_string(), self.store.get_raw(b.id)[1]) |
178 |
||
179 |
def test_contains(self): |
|
180 |
b = Blob() |
|
181 |
b.data = 'a\nb\nc\nd\ne\n' |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
182 |
self.store.lock_read() |
183 |
self.addCleanup(self.store.unlock) |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
184 |
self.assertFalse(b.id in self.store) |
185 |
bb = BranchBuilder(branch=self.branch) |
|
186 |
bb.start_series() |
|
187 |
bb.build_snapshot('BASE-id', None, |
|
188 |
[('add', ('', None, 'directory', None)), |
|
189 |
('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')), |
|
190 |
])
|
|
191 |
bb.finish_series() |
|
|
0.200.1212
by Jelmer Vernooij
Support read locking object stores. |
192 |
# read locks cache
|
193 |
self.assertFalse(b.id in self.store) |
|
194 |
self.store.unlock() |
|
195 |
self.store.lock_read() |
|
|
0.200.964
by Jelmer Vernooij
Add some tests for object store. |
196 |
self.assertTrue(b.id in self.store) |
197 |
||
|
0.200.1016
by Jelmer Vernooij
add basic test for tree_to_objects. |
198 |
|
199 |
class TreeToObjectsTests(TestCaseWithTransport): |
|
200 |
||
201 |
def setUp(self): |
|
202 |
super(TreeToObjectsTests, self).setUp() |
|
203 |
self.idmap = DictGitShaMap() |
|
204 |
||
205 |
def test_no_changes(self): |
|
206 |
tree = self.make_branch_and_tree('.') |
|
207 |
entries = list(_tree_to_objects(tree, [tree], self.idmap, {})) |
|
208 |
self.assertEquals([], entries) |