/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_object_store.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-05 18:26:04 UTC
  • mfrom: (0.200.1933 work)
  • mto: (0.200.1934 work)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180505182604-rf3zyekbhwhlwddi
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from dulwich.objects import (
22
22
    Blob,
 
23
    Tree,
23
24
    )
24
25
 
25
26
from ....branchbuilder import (
26
27
    BranchBuilder,
27
28
    )
 
29
from ....bzr.inventory import (
 
30
    InventoryDirectory,
 
31
    InventoryFile,
 
32
    )
28
33
from ....errors import (
29
34
    NoSuchRevision,
30
35
    )
43
48
from ..object_store import (
44
49
    BazaarObjectStore,
45
50
    LRUTreeCache,
 
51
    directory_to_tree,
46
52
    _check_expected_sha,
47
53
    _find_missing_bzr_revids,
48
54
    _tree_to_objects,
61
67
 
62
68
    def test_hex(self):
63
69
        _check_expected_sha(self.obj.sha().hexdigest(), self.obj)
64
 
        self.assertRaises(AssertionError, _check_expected_sha, 
 
70
        self.assertRaises(AssertionError, _check_expected_sha,
65
71
            "0" * 40, self.obj)
66
72
 
67
73
    def test_binary(self):
68
74
        _check_expected_sha(self.obj.sha().digest(), self.obj)
69
 
        self.assertRaises(AssertionError, _check_expected_sha, 
 
75
        self.assertRaises(AssertionError, _check_expected_sha,
70
76
            "x" * 20, self.obj)
71
77
 
72
78
 
209
215
        self.addCleanup(tree.lock_read().unlock)
210
216
        entries = list(_tree_to_objects(tree, [tree], self.idmap, {}))
211
217
        self.assertEquals([], entries)
 
218
 
 
219
    def test_with_gitdir(self):
 
220
        tree = self.make_branch_and_tree('.')
 
221
        self.build_tree(['.git', 'foo'])
 
222
        tree.add(['.git', 'foo'])
 
223
        revid = tree.commit('commit')
 
224
        revtree = tree.branch.repository.revision_tree(revid)
 
225
        self.addCleanup(revtree.lock_read().unlock)
 
226
        entries = list(_tree_to_objects(revtree, [], self.idmap, {}))
 
227
        self.assertEquals(['foo', ''], [p[0] for p in entries])
 
228
 
 
229
 
 
230
class DirectoryToTreeTests(TestCase):
 
231
 
 
232
    def test_empty(self):
 
233
        t = directory_to_tree('', [], None, {}, None, allow_empty=False)
 
234
        self.assertEquals(None, t)
 
235
 
 
236
    def test_empty_dir(self):
 
237
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
238
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, None,
 
239
                allow_empty=False)
 
240
        self.assertEquals(None, t)
 
241
 
 
242
    def test_empty_dir_dummy_files(self):
 
243
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
244
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, ".mydummy",
 
245
                allow_empty=False)
 
246
        self.assertTrue(".mydummy" in t)
 
247
 
 
248
    def test_empty_root(self):
 
249
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
250
        t = directory_to_tree('', [child_ie], lambda p, x: None, {}, None,
 
251
                allow_empty=True)
 
252
        self.assertEquals(Tree(), t)
 
253
 
 
254
    def test_with_file(self):
 
255
        child_ie = InventoryFile('bar', 'bar', 'bar')
 
256
        b = Blob.from_string("bla")
 
257
        t1 = directory_to_tree('', [child_ie], lambda p, x: b.id, {}, None,
 
258
                allow_empty=False)
 
259
        t2 = Tree()
 
260
        t2.add("bar", 0100644, b.id)
 
261
        self.assertEquals(t1, t2)
 
262
 
 
263
    def test_with_gitdir(self):
 
264
        child_ie = InventoryFile('bar', 'bar', 'bar')
 
265
        git_file_ie = InventoryFile('gitid', '.git', 'bar')
 
266
        b = Blob.from_string("bla")
 
267
        t1 = directory_to_tree('', [child_ie, git_file_ie],
 
268
                lambda p, x: b.id, {}, None,
 
269
                allow_empty=False)
 
270
        t2 = Tree()
 
271
        t2.add("bar", 0100644, b.id)
 
272
        self.assertEquals(t1, t2)