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