/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_cache.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) 2009 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 GitShaMap."""
18
 
 
19
 
from dulwich.objects import (
20
 
    Blob,
21
 
    Commit,
22
 
    Tree,
23
 
    )
24
 
 
25
 
import os
26
 
import stat
27
 
 
28
 
from bzrlib import osutils
29
 
 
30
 
from bzrlib.inventory import (
31
 
    InventoryFile,
32
 
    InventoryDirectory,
33
 
    ROOT_ID,
34
 
    )
35
 
 
36
 
from bzrlib.revision import (
37
 
    Revision,
38
 
    )
39
 
 
40
 
from bzrlib.tests import (
41
 
    TestCase,
42
 
    TestCaseInTempDir,
43
 
    UnavailableFeature,
44
 
    )
45
 
from bzrlib.transport import (
46
 
    get_transport,
47
 
    )
48
 
 
49
 
from bzrlib.plugins.git.cache import (
50
 
    DictBzrGitCache,
51
 
    IndexBzrGitCache,
52
 
    IndexGitCacheFormat,
53
 
    SqliteBzrGitCache,
54
 
    TdbBzrGitCache,
55
 
    )
56
 
 
57
 
class TestGitShaMap:
58
 
 
59
 
    def _get_test_commit(self):
60
 
        c = Commit()
61
 
        c.committer = "Jelmer <jelmer@samba.org>"
62
 
        c.commit_time = 0
63
 
        c.commit_timezone = 0
64
 
        c.author = "Jelmer <jelmer@samba.org>"
65
 
        c.author_time = 0
66
 
        c.author_timezone = 0
67
 
        c.message = "Teh foo bar"
68
 
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
69
 
        return c
70
 
 
71
 
    def test_commit(self):
72
 
        self.map.start_write_group()
73
 
        updater = self.cache.get_updater(Revision("myrevid"))
74
 
        c = self._get_test_commit()
75
 
        updater.add_object(c, {
76
 
            "testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
77
 
            None)
78
 
        updater.finish()
79
 
        self.map.commit_write_group()
80
 
        self.assertEquals(
81
 
            [("commit", ("myrevid",
82
 
                "cc9462f7f8263ef5adfbeff2fb936bb36b504cba",
83
 
                {"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
84
 
                ))],
85
 
            list(self.map.lookup_git_sha(c.id)))
86
 
        self.assertEquals(c.id, self.map.lookup_commit("myrevid"))
87
 
 
88
 
    def test_lookup_notfound(self):
89
 
        self.assertRaises(KeyError, list,
90
 
            self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
91
 
 
92
 
    def test_blob(self):
93
 
        self.map.start_write_group()
94
 
        updater = self.cache.get_updater(Revision("myrevid"))
95
 
        updater.add_object(self._get_test_commit(), { "testament3-sha1": "Test" }, None)
96
 
        b = Blob()
97
 
        b.data = "TEH BLOB"
98
 
        ie = InventoryFile("myfileid", "somename", ROOT_ID)
99
 
        ie.revision = "myrevid"
100
 
        updater.add_object(b, ie, None)
101
 
        updater.finish()
102
 
        self.map.commit_write_group()
103
 
        self.assertEquals(
104
 
            [("blob", ("myfileid", "myrevid"))],
105
 
            list(self.map.lookup_git_sha(b.id)))
106
 
        self.assertEquals(b.id,
107
 
            self.map.lookup_blob_id("myfileid", "myrevid"))
108
 
 
109
 
    def test_tree(self):
110
 
        self.map.start_write_group()
111
 
        updater = self.cache.get_updater(Revision("myrevid"))
112
 
        updater.add_object(self._get_test_commit(), {
113
 
            "testament3-sha1": "mytestamentsha" }, None)
114
 
        t = Tree()
115
 
        t.add("somename", stat.S_IFREG, Blob().id)
116
 
        ie = InventoryDirectory("fileid", "myname", ROOT_ID)
117
 
        ie.revision = "irrelevant"
118
 
        updater.add_object(t, ie, "")
119
 
        updater.finish()
120
 
        self.map.commit_write_group()
121
 
        self.assertEquals([("tree", ("fileid", "myrevid"))],
122
 
            list(self.map.lookup_git_sha(t.id)))
123
 
        # It's possible for a backend to not implement lookup_tree
124
 
        try:
125
 
            self.assertEquals(t.id,
126
 
                self.map.lookup_tree_id("fileid", "myrevid"))
127
 
        except NotImplementedError:
128
 
            pass
129
 
 
130
 
    def test_revids(self):
131
 
        self.map.start_write_group()
132
 
        updater = self.cache.get_updater(Revision("myrevid"))
133
 
        c = self._get_test_commit()
134
 
        updater.add_object(c, {"testament3-sha1": "mtestament"}, None)
135
 
        updater.finish()
136
 
        self.map.commit_write_group()
137
 
        self.assertEquals(["myrevid"], list(self.map.revids()))
138
 
 
139
 
    def test_missing_revisions(self):
140
 
        self.map.start_write_group()
141
 
        updater = self.cache.get_updater(Revision("myrevid"))
142
 
        c = self._get_test_commit()
143
 
        updater.add_object(c, {"testament3-sha1": "testament"}, None)
144
 
        updater.finish()
145
 
        self.map.commit_write_group()
146
 
        self.assertEquals(set(["lala", "bla"]),
147
 
            set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
148
 
 
149
 
 
150
 
class DictGitShaMapTests(TestCase,TestGitShaMap):
151
 
 
152
 
    def setUp(self):
153
 
        TestCase.setUp(self)
154
 
        self.cache = DictBzrGitCache()
155
 
        self.map = self.cache.idmap
156
 
 
157
 
 
158
 
class SqliteGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
159
 
 
160
 
    def setUp(self):
161
 
        TestCaseInTempDir.setUp(self)
162
 
        self.cache = SqliteBzrGitCache(os.path.join(self.test_dir, 'foo.db'))
163
 
        self.map = self.cache.idmap
164
 
 
165
 
 
166
 
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
167
 
 
168
 
    def setUp(self):
169
 
        TestCaseInTempDir.setUp(self)
170
 
        try:
171
 
            self.cache = TdbBzrGitCache(
172
 
                os.path.join(self.test_dir, 'foo.tdb').encode(osutils._fs_enc))
173
 
        except ImportError:
174
 
            raise UnavailableFeature("Missing tdb")
175
 
        self.map = self.cache.idmap
176
 
 
177
 
 
178
 
class IndexGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
179
 
 
180
 
    def setUp(self):
181
 
        TestCaseInTempDir.setUp(self)
182
 
        transport = get_transport(self.test_dir)
183
 
        IndexGitCacheFormat().initialize(transport)
184
 
        self.cache = IndexBzrGitCache(transport)
185
 
        self.map = self.cache.idmap