/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
23
 
from bzrlib.branchbuilder import (
24
 
    BranchBuilder,
25
 
    )
26
 
from bzrlib.errors import (
27
 
    NoSuchRevision,
28
 
    )
29
 
from bzrlib.graph import (
30
 
    DictParentsProvider,
31
 
    )
32
 
from bzrlib.tests import (
33
 
    TestCase,
34
 
    TestCaseWithTransport,
35
 
    )
36
 
 
37
 
from bzrlib.plugins.git.cache import (
38
 
    DictGitShaMap,
39
 
    )
40
 
from bzrlib.plugins.git.object_store import (
41
 
    BazaarObjectStore,
42
 
    LRUTreeCache,
43
 
    _check_expected_sha,
44
 
    _find_missing_bzr_revids,
45
 
    _tree_to_objects,
46
 
    )
47
 
 
48
 
 
49
 
class ExpectedShaTests(TestCase):
50
 
 
51
 
    def setUp(self):
52
 
        super(ExpectedShaTests, self).setUp()
53
 
        self.obj = Blob()
54
 
        self.obj.data = "foo"
55
 
 
56
 
    def test_none(self):
57
 
        _check_expected_sha(None, self.obj)
58
 
 
59
 
    def test_hex(self):
60
 
        _check_expected_sha(self.obj.sha().hexdigest(), self.obj)
61
 
        self.assertRaises(AssertionError, _check_expected_sha, 
62
 
            "0" * 40, self.obj)
63
 
 
64
 
    def test_binary(self):
65
 
        _check_expected_sha(self.obj.sha().digest(), self.obj)
66
 
        self.assertRaises(AssertionError, _check_expected_sha, 
67
 
            "x" * 20, self.obj)
68
 
 
69
 
 
70
 
class FindMissingBzrRevidsTests(TestCase):
71
 
 
72
 
    def _find_missing(self, ancestry, want, have):
73
 
        return _find_missing_bzr_revids(
74
 
            DictParentsProvider(ancestry).get_parent_map,
75
 
            set(want), set(have))
76
 
 
77
 
    def test_simple(self):
78
 
        self.assertEquals(set(), self._find_missing({}, [], []))
79
 
 
80
 
    def test_up_to_date(self):
81
 
        self.assertEquals(set(),
82
 
                self._find_missing({"a": ["b"]}, ["a"], ["a"]))
83
 
 
84
 
    def test_one_missing(self):
85
 
        self.assertEquals(set(["a"]),
86
 
                self._find_missing({"a": ["b"]}, ["a"], ["b"]))
87
 
 
88
 
    def test_two_missing(self):
89
 
        self.assertEquals(set(["a", "b"]),
90
 
                self._find_missing({"a": ["b"], "b": ["c"]}, ["a"], ["c"]))
91
 
 
92
 
    def test_two_missing_history(self):
93
 
        self.assertEquals(set(["a", "b"]),
94
 
                self._find_missing({"a": ["b"], "b": ["c"], "c": ["d"]},
95
 
                    ["a"], ["c"]))
96
 
 
97
 
 
98
 
class LRUTreeCacheTests(TestCaseWithTransport):
99
 
 
100
 
    def setUp(self):
101
 
        super(LRUTreeCacheTests, self).setUp()
102
 
        self.branch = self.make_branch(".")
103
 
        self.branch.lock_write()
104
 
        self.addCleanup(self.branch.unlock)
105
 
        self.cache = LRUTreeCache(self.branch.repository)
106
 
 
107
 
    def test_get_not_present(self):
108
 
        self.assertRaises(NoSuchRevision, self.cache.revision_tree,
109
 
                "unknown")
110
 
 
111
 
    def test_revision_trees(self):
112
 
        self.assertRaises(NoSuchRevision, self.cache.revision_trees,
113
 
                ["unknown", "la"])
114
 
 
115
 
    def test_iter_revision_trees(self):
116
 
        self.assertRaises(NoSuchRevision, self.cache.iter_revision_trees,
117
 
                ["unknown", "la"])
118
 
 
119
 
    def test_get(self):
120
 
        bb = BranchBuilder(branch=self.branch)
121
 
        bb.start_series()
122
 
        bb.build_snapshot('BASE-id', None,
123
 
            [('add', ('', None, 'directory', None)),
124
 
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
125
 
             ])
126
 
        bb.finish_series()
127
 
        tree = self.cache.revision_tree("BASE-id")
128
 
        self.assertEquals("BASE-id", tree.get_revision_id())
129
 
 
130
 
 
131
 
class BazaarObjectStoreTests(TestCaseWithTransport):
132
 
 
133
 
    def setUp(self):
134
 
        super(BazaarObjectStoreTests, self).setUp()
135
 
        self.branch = self.make_branch(".")
136
 
        self.branch.lock_write()
137
 
        self.addCleanup(self.branch.unlock)
138
 
        self.store = BazaarObjectStore(self.branch.repository)
139
 
 
140
 
    def test_get_blob(self):
141
 
        b = Blob()
142
 
        b.data = 'a\nb\nc\nd\ne\n'
143
 
        self.assertRaises(KeyError, self.store.__getitem__, b.id)
144
 
        bb = BranchBuilder(branch=self.branch)
145
 
        bb.start_series()
146
 
        bb.build_snapshot('BASE-id', None,
147
 
            [('add', ('', None, 'directory', None)),
148
 
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
149
 
             ])
150
 
        bb.finish_series()
151
 
        self.assertEquals(b, self.store[b.id])
152
 
 
153
 
    def test_get_raw(self):
154
 
        b = Blob()
155
 
        b.data = 'a\nb\nc\nd\ne\n'
156
 
        self.assertRaises(KeyError, self.store.get_raw, b.id)
157
 
        bb = BranchBuilder(branch=self.branch)
158
 
        bb.start_series()
159
 
        bb.build_snapshot('BASE-id', None,
160
 
            [('add', ('', None, 'directory', None)),
161
 
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
162
 
             ])
163
 
        bb.finish_series()
164
 
        self.assertEquals(b.as_raw_string(), self.store.get_raw(b.id)[1])
165
 
 
166
 
    def test_contains(self):
167
 
        b = Blob()
168
 
        b.data = 'a\nb\nc\nd\ne\n'
169
 
        self.assertFalse(b.id in self.store)
170
 
        bb = BranchBuilder(branch=self.branch)
171
 
        bb.start_series()
172
 
        bb.build_snapshot('BASE-id', None,
173
 
            [('add', ('', None, 'directory', None)),
174
 
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
175
 
             ])
176
 
        bb.finish_series()
177
 
        self.assertTrue(b.id in self.store)
178
 
 
179
 
 
180
 
class TreeToObjectsTests(TestCaseWithTransport):
181
 
 
182
 
    def setUp(self):
183
 
        super(TreeToObjectsTests, self).setUp()
184
 
        self.idmap = DictGitShaMap()
185
 
 
186
 
    def test_no_changes(self):
187
 
        tree = self.make_branch_and_tree('.')
188
 
        entries = list(_tree_to_objects(tree, [tree], self.idmap, {}))
189
 
        self.assertEquals([], entries)