/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
16
17
"""Tests for bzr-git's object store."""
18
0.358.3 by Jelmer Vernooij
Enable absolute import.
19
from __future__ import absolute_import
20
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
21
from dulwich.objects import (
22
    Blob,
0.421.3 by Jelmer Vernooij
Move directory_to_tree to object_store.
23
    Tree,
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
24
    )
25
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
26
from ....branchbuilder import (
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
27
    BranchBuilder,
28
    )
0.421.3 by Jelmer Vernooij
Move directory_to_tree to object_store.
29
from ....bzr.inventory import (
30
    InventoryDirectory,
31
    InventoryFile,
32
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
33
from ....errors import (
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
34
    NoSuchRevision,
35
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
36
from ....graph import (
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
37
    DictParentsProvider,
0.200.1059 by Jelmer Vernooij
Fix graph tests.
38
    Graph,
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
39
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
40
from ....tests import (
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
41
    TestCase,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
42
    TestCaseWithTransport,
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
43
    )
44
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
45
from ..cache import (
0.200.1016 by Jelmer Vernooij
add basic test for tree_to_objects.
46
    DictGitShaMap,
47
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
48
from ..object_store import (
0.200.964 by Jelmer Vernooij
Add some tests for object store.
49
    BazaarObjectStore,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
50
    LRUTreeCache,
0.421.3 by Jelmer Vernooij
Move directory_to_tree to object_store.
51
    directory_to_tree,
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
52
    _check_expected_sha,
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
53
    _find_missing_bzr_revids,
0.200.1016 by Jelmer Vernooij
add basic test for tree_to_objects.
54
    _tree_to_objects,
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
55
    )
56
57
58
class ExpectedShaTests(TestCase):
59
60
    def setUp(self):
61
        super(ExpectedShaTests, self).setUp()
62
        self.obj = Blob()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
63
        self.obj.data = b"foo"
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
64
65
    def test_none(self):
66
        _check_expected_sha(None, self.obj)
67
68
    def test_hex(self):
7027.2.1 by Jelmer Vernooij
Port fastimport to python3.
69
        _check_expected_sha(
70
                self.obj.sha().hexdigest().encode('ascii'), self.obj)
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
71
        self.assertRaises(AssertionError, _check_expected_sha,
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
72
            b"0" * 40, self.obj)
0.200.799 by Jelmer Vernooij
Add trivial object store tests.
73
74
    def test_binary(self):
75
        _check_expected_sha(self.obj.sha().digest(), self.obj)
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
76
        self.assertRaises(AssertionError, _check_expected_sha,
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
77
            b"x" * 20, self.obj)
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
78
79
80
class FindMissingBzrRevidsTests(TestCase):
81
82
    def _find_missing(self, ancestry, want, have):
83
        return _find_missing_bzr_revids(
0.200.1059 by Jelmer Vernooij
Fix graph tests.
84
            Graph(DictParentsProvider(ancestry)),
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
85
            set(want), set(have))
86
87
    def test_simple(self):
6964.2.3 by Jelmer Vernooij
Review comments.
88
        self.assertEqual(set(), self._find_missing({}, [], []))
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
89
90
    def test_up_to_date(self):
6964.2.3 by Jelmer Vernooij
Review comments.
91
        self.assertEqual(set(),
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
92
                self._find_missing({"a": ["b"]}, ["a"], ["a"]))
93
94
    def test_one_missing(self):
6964.2.3 by Jelmer Vernooij
Review comments.
95
        self.assertEqual(set(["a"]),
0.200.899 by Jelmer Vernooij
Add tests for find_missing_bzr_revids.
96
                self._find_missing({"a": ["b"]}, ["a"], ["b"]))
0.200.905 by Jelmer Vernooij
More find missing revision tests.
97
98
    def test_two_missing(self):
6964.2.3 by Jelmer Vernooij
Review comments.
99
        self.assertEqual(set(["a", "b"]),
0.200.905 by Jelmer Vernooij
More find missing revision tests.
100
                self._find_missing({"a": ["b"], "b": ["c"]}, ["a"], ["c"]))
101
102
    def test_two_missing_history(self):
6964.2.3 by Jelmer Vernooij
Review comments.
103
        self.assertEqual(set(["a", "b"]),
0.200.905 by Jelmer Vernooij
More find missing revision tests.
104
                self._find_missing({"a": ["b"], "b": ["c"], "c": ["d"]},
105
                    ["a"], ["c"]))
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
106
107
108
class LRUTreeCacheTests(TestCaseWithTransport):
109
110
    def setUp(self):
111
        super(LRUTreeCacheTests, self).setUp()
112
        self.branch = self.make_branch(".")
113
        self.branch.lock_write()
114
        self.addCleanup(self.branch.unlock)
115
        self.cache = LRUTreeCache(self.branch.repository)
116
117
    def test_get_not_present(self):
0.200.965 by Jelmer Vernooij
Formatting fixes.
118
        self.assertRaises(NoSuchRevision, self.cache.revision_tree,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
119
                "unknown")
120
121
    def test_revision_trees(self):
0.200.965 by Jelmer Vernooij
Formatting fixes.
122
        self.assertRaises(NoSuchRevision, self.cache.revision_trees,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
123
                ["unknown", "la"])
124
125
    def test_iter_revision_trees(self):
0.200.965 by Jelmer Vernooij
Formatting fixes.
126
        self.assertRaises(NoSuchRevision, self.cache.iter_revision_trees,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
127
                ["unknown", "la"])
128
129
    def test_get(self):
130
        bb = BranchBuilder(branch=self.branch)
131
        bb.start_series()
0.285.8 by Jelmer Vernooij
Fix more tests for swapped arguments.
132
        revid = bb.build_snapshot(None,
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
133
            [('add', ('', None, 'directory', None)),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
134
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
0.200.963 by Jelmer Vernooij
Add some tests for LRUTreeCache.
135
             ])
136
        bb.finish_series()
0.285.8 by Jelmer Vernooij
Fix more tests for swapped arguments.
137
        tree = self.cache.revision_tree(revid)
6964.2.3 by Jelmer Vernooij
Review comments.
138
        self.assertEqual(revid, tree.get_revision_id())
0.200.964 by Jelmer Vernooij
Add some tests for object store.
139
140
141
class BazaarObjectStoreTests(TestCaseWithTransport):
142
143
    def setUp(self):
144
        super(BazaarObjectStoreTests, self).setUp()
145
        self.branch = self.make_branch(".")
146
        self.branch.lock_write()
147
        self.addCleanup(self.branch.unlock)
148
        self.store = BazaarObjectStore(self.branch.repository)
149
150
    def test_get_blob(self):
151
        b = Blob()
6973.5.10 by Jelmer Vernooij
Random bunch of python3 bee-improvements.
152
        b.data = b'a\nb\nc\nd\ne\n'
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
153
        self.store.lock_read()
154
        self.addCleanup(self.store.unlock)
0.200.964 by Jelmer Vernooij
Add some tests for object store.
155
        self.assertRaises(KeyError, self.store.__getitem__, b.id)
156
        bb = BranchBuilder(branch=self.branch)
157
        bb.start_series()
0.285.8 by Jelmer Vernooij
Fix more tests for swapped arguments.
158
        bb.build_snapshot(None,
0.200.964 by Jelmer Vernooij
Add some tests for object store.
159
            [('add', ('', None, 'directory', None)),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
160
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
0.200.964 by Jelmer Vernooij
Add some tests for object store.
161
             ])
162
        bb.finish_series()
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
163
        # read locks cache
164
        self.assertRaises(KeyError, self.store.__getitem__, b.id)
165
        self.store.unlock()
166
        self.store.lock_read()
6964.2.3 by Jelmer Vernooij
Review comments.
167
        self.assertEqual(b, self.store[b.id])
0.200.964 by Jelmer Vernooij
Add some tests for object store.
168
169
    def test_get_raw(self):
170
        b = Blob()
6973.5.10 by Jelmer Vernooij
Random bunch of python3 bee-improvements.
171
        b.data = b'a\nb\nc\nd\ne\n'
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
172
        self.store.lock_read()
173
        self.addCleanup(self.store.unlock)
0.200.964 by Jelmer Vernooij
Add some tests for object store.
174
        self.assertRaises(KeyError, self.store.get_raw, b.id)
175
        bb = BranchBuilder(branch=self.branch)
176
        bb.start_series()
0.285.8 by Jelmer Vernooij
Fix more tests for swapped arguments.
177
        bb.build_snapshot(None,
0.200.964 by Jelmer Vernooij
Add some tests for object store.
178
            [('add', ('', None, 'directory', None)),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
179
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
0.200.964 by Jelmer Vernooij
Add some tests for object store.
180
             ])
181
        bb.finish_series()
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
182
        # read locks cache
183
        self.assertRaises(KeyError, self.store.get_raw, b.id)
184
        self.store.unlock()
185
        self.store.lock_read()
6964.2.3 by Jelmer Vernooij
Review comments.
186
        self.assertEqual(b.as_raw_string(), self.store.get_raw(b.id)[1])
0.200.964 by Jelmer Vernooij
Add some tests for object store.
187
188
    def test_contains(self):
189
        b = Blob()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
190
        b.data = b'a\nb\nc\nd\ne\n'
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
191
        self.store.lock_read()
192
        self.addCleanup(self.store.unlock)
0.200.964 by Jelmer Vernooij
Add some tests for object store.
193
        self.assertFalse(b.id in self.store)
194
        bb = BranchBuilder(branch=self.branch)
195
        bb.start_series()
0.285.8 by Jelmer Vernooij
Fix more tests for swapped arguments.
196
        bb.build_snapshot(None,
0.200.964 by Jelmer Vernooij
Add some tests for object store.
197
            [('add', ('', None, 'directory', None)),
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
198
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
0.200.964 by Jelmer Vernooij
Add some tests for object store.
199
             ])
200
        bb.finish_series()
0.200.1212 by Jelmer Vernooij
Support read locking object stores.
201
        # read locks cache
202
        self.assertFalse(b.id in self.store)
203
        self.store.unlock()
204
        self.store.lock_read()
0.200.964 by Jelmer Vernooij
Add some tests for object store.
205
        self.assertTrue(b.id in self.store)
206
0.200.1016 by Jelmer Vernooij
add basic test for tree_to_objects.
207
208
class TreeToObjectsTests(TestCaseWithTransport):
209
210
    def setUp(self):
211
        super(TreeToObjectsTests, self).setUp()
212
        self.idmap = DictGitShaMap()
213
214
    def test_no_changes(self):
215
        tree = self.make_branch_and_tree('.')
0.275.5 by Jelmer Vernooij
Cope with root_inventory and inventory.
216
        self.addCleanup(tree.lock_read().unlock)
0.200.1016 by Jelmer Vernooij
add basic test for tree_to_objects.
217
        entries = list(_tree_to_objects(tree, [tree], self.idmap, {}))
6964.2.3 by Jelmer Vernooij
Review comments.
218
        self.assertEqual([], entries)
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
219
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
220
    def test_with_gitdir(self):
221
        tree = self.make_branch_and_tree('.')
222
        self.build_tree(['.git', 'foo'])
223
        tree.add(['.git', 'foo'])
224
        revid = tree.commit('commit')
225
        revtree = tree.branch.repository.revision_tree(revid)
226
        self.addCleanup(revtree.lock_read().unlock)
227
        entries = list(_tree_to_objects(revtree, [], self.idmap, {}))
6964.2.3 by Jelmer Vernooij
Review comments.
228
        self.assertEqual(['foo', ''], [p[0] for p in entries])
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
229
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
230
0.421.3 by Jelmer Vernooij
Move directory_to_tree to object_store.
231
class DirectoryToTreeTests(TestCase):
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
232
233
    def test_empty(self):
0.421.6 by Jelmer Vernooij
Some more simplifications.
234
        t = directory_to_tree('', [], None, {}, None, allow_empty=False)
6964.2.3 by Jelmer Vernooij
Review comments.
235
        self.assertEqual(None, t)
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
236
237
    def test_empty_dir(self):
6973.11.6 by Jelmer Vernooij
Fix more http tests.
238
        child_ie = InventoryDirectory(b'bar', 'bar', b'bar')
0.421.6 by Jelmer Vernooij
Some more simplifications.
239
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, None,
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
240
                allow_empty=False)
6964.2.3 by Jelmer Vernooij
Review comments.
241
        self.assertEqual(None, t)
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
242
243
    def test_empty_dir_dummy_files(self):
6973.11.6 by Jelmer Vernooij
Fix more http tests.
244
        child_ie = InventoryDirectory(b'bar', 'bar', b'bar')
0.421.6 by Jelmer Vernooij
Some more simplifications.
245
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, ".mydummy",
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
246
                allow_empty=False)
247
        self.assertTrue(".mydummy" in t)
248
249
    def test_empty_root(self):
6973.11.6 by Jelmer Vernooij
Fix more http tests.
250
        child_ie = InventoryDirectory(b'bar', 'bar', b'bar')
0.421.6 by Jelmer Vernooij
Some more simplifications.
251
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, None,
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
252
                allow_empty=True)
6964.2.3 by Jelmer Vernooij
Review comments.
253
        self.assertEqual(Tree(), t)
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
254
255
    def test_with_file(self):
6973.11.6 by Jelmer Vernooij
Fix more http tests.
256
        child_ie = InventoryFile(b'bar', 'bar', b'bar')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
257
        b = Blob.from_string(b"bla")
0.421.6 by Jelmer Vernooij
Some more simplifications.
258
        t1 = directory_to_tree('', [child_ie], lambda p, x: b.id, {}, None,
0.421.2 by Jelmer Vernooij
Move directory_to_tree.
259
                allow_empty=False)
260
        t2 = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
261
        t2.add(b"bar", 0o100644, b.id)
6964.2.3 by Jelmer Vernooij
Review comments.
262
        self.assertEqual(t1, t2)
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
263
264
    def test_with_gitdir(self):
6973.11.6 by Jelmer Vernooij
Fix more http tests.
265
        child_ie = InventoryFile(b'bar', 'bar', b'bar')
266
        git_file_ie = InventoryFile(b'gitid', '.git', b'bar')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
267
        b = Blob.from_string(b"bla")
0.424.1 by Jelmer Vernooij
Fix error message about .git directory.
268
        t1 = directory_to_tree('', [child_ie, git_file_ie],
269
                lambda p, x: b.id, {}, None,
270
                allow_empty=False)
271
        t2 = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
272
        t2.add(b"bar", 0o100644, b.id)
6964.2.3 by Jelmer Vernooij
Review comments.
273
        self.assertEqual(t1, t2)