/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

Add some basic documentation in 'bzr help git'.

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