/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
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
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
19
from dulwich.objects import (
0.200.850 by Jelmer Vernooij
Fix tests.
20
    Blob,
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
21
    Commit,
0.200.850 by Jelmer Vernooij
Fix tests.
22
    Tree,
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
23
    )
24
0.200.475 by Jelmer Vernooij
Add Tdb database backend.
25
import os
0.200.850 by Jelmer Vernooij
Fix tests.
26
import stat
27
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
28
from .... import osutils
0.200.1075 by Jelmer Vernooij
Fix compatibility with older versions of python-tdb.
29
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
30
from ....bzr.inventory import (
0.200.850 by Jelmer Vernooij
Fix tests.
31
    InventoryFile,
32
    InventoryDirectory,
33
    ROOT_ID,
34
    )
0.200.475 by Jelmer Vernooij
Add Tdb database backend.
35
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
36
from ....revision import (
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
37
    Revision,
38
    )
39
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
40
from ....tests import (
0.200.475 by Jelmer Vernooij
Add Tdb database backend.
41
    TestCase,
42
    TestCaseInTempDir,
43
    UnavailableFeature,
44
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
45
from ....transport import (
0.254.1 by Jelmer Vernooij
Add trivial index-based sha map.
46
    get_transport,
47
    )
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
48
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
49
from ..cache import (
0.254.46 by Jelmer Vernooij
Merge trunk.
50
    DictBzrGitCache,
51
    IndexBzrGitCache,
0.200.952 by Jelmer Vernooij
Write git pack files rather than loose objects.
52
    IndexGitCacheFormat,
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
53
    SqliteBzrGitCache,
54
    TdbBzrGitCache,
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
55
    )
56
57
class TestGitShaMap:
58
0.200.850 by Jelmer Vernooij
Fix tests.
59
    def _get_test_commit(self):
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
60
        c = Commit()
61
        c.committer = "Jelmer <jelmer@samba.org>"
0.200.850 by Jelmer Vernooij
Fix tests.
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
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
67
        c.message = "Teh foo bar"
68
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
0.200.850 by Jelmer Vernooij
Fix tests.
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()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
75
        updater.add_object(c, {
76
            "testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
77
            None)
0.200.850 by Jelmer Vernooij
Fix tests.
78
        updater.finish()
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
79
        self.map.commit_write_group()
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
80
        self.assertEquals(
0.261.1 by Jelmer Vernooij
Initial work on supporting multiple results for git shas.
81
            [("commit", ("myrevid",
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
82
                "cc9462f7f8263ef5adfbeff2fb936bb36b504cba",
83
                {"testament3-sha1": "cc9462f7f8263ef5adf8eff2fb936bb36b504cba"},
0.261.1 by Jelmer Vernooij
Initial work on supporting multiple results for git shas.
84
                ))],
85
            list(self.map.lookup_git_sha(c.id)))
0.200.853 by Jelmer Vernooij
Fix lookup of commits in tdb.
86
        self.assertEquals(c.id, self.map.lookup_commit("myrevid"))
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
87
88
    def test_lookup_notfound(self):
0.261.2 by Jelmer Vernooij
Fix cache tests.
89
        self.assertRaises(KeyError, list,
90
            self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
91
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
92
    def test_blob(self):
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
93
        self.map.start_write_group()
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
94
        updater = self.cache.get_updater(Revision("myrevid"))
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
95
        updater.add_object(self._get_test_commit(), { "testament3-sha1": "Test" }, None)
0.200.850 by Jelmer Vernooij
Fix tests.
96
        b = Blob()
97
        b.data = "TEH BLOB"
0.275.2 by Jelmer Vernooij
Pass tuples around for cache entries, rather than inventory entries.
98
        updater.add_object(b, ("myfileid", "myrevid"), None)
0.200.850 by Jelmer Vernooij
Fix tests.
99
        updater.finish()
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
100
        self.map.commit_write_group()
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
101
        self.assertEquals(
0.261.1 by Jelmer Vernooij
Initial work on supporting multiple results for git shas.
102
            [("blob", ("myfileid", "myrevid"))],
103
            list(self.map.lookup_git_sha(b.id)))
0.200.850 by Jelmer Vernooij
Fix tests.
104
        self.assertEquals(b.id,
0.200.841 by Jelmer Vernooij
Eliminate InventorySHAMap.
105
            self.map.lookup_blob_id("myfileid", "myrevid"))
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
106
107
    def test_tree(self):
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
108
        self.map.start_write_group()
0.200.850 by Jelmer Vernooij
Fix tests.
109
        updater = self.cache.get_updater(Revision("myrevid"))
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
110
        updater.add_object(self._get_test_commit(), {
111
            "testament3-sha1": "mytestamentsha" }, None)
0.200.850 by Jelmer Vernooij
Fix tests.
112
        t = Tree()
0.200.1152 by Jelmer Vernooij
Require dulwich 0.7.1.
113
        t.add("somename", stat.S_IFREG, Blob().id)
0.275.2 by Jelmer Vernooij
Pass tuples around for cache entries, rather than inventory entries.
114
        updater.add_object(t, ("fileid", ), "")
0.200.850 by Jelmer Vernooij
Fix tests.
115
        updater.finish()
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
116
        self.map.commit_write_group()
0.261.1 by Jelmer Vernooij
Initial work on supporting multiple results for git shas.
117
        self.assertEquals([("tree", ("fileid", "myrevid"))],
118
            list(self.map.lookup_git_sha(t.id)))
0.200.860 by Jelmer Vernooij
Fix bugs in two lookup_tree_id implementations and add a test for it.
119
        # It's possible for a backend to not implement lookup_tree
120
        try:
121
            self.assertEquals(t.id,
122
                self.map.lookup_tree_id("fileid", "myrevid"))
123
        except NotImplementedError:
124
            pass
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
125
126
    def test_revids(self):
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
127
        self.map.start_write_group()
0.200.850 by Jelmer Vernooij
Fix tests.
128
        updater = self.cache.get_updater(Revision("myrevid"))
129
        c = self._get_test_commit()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
130
        updater.add_object(c, {"testament3-sha1": "mtestament"}, None)
0.200.850 by Jelmer Vernooij
Fix tests.
131
        updater.finish()
0.200.687 by Jelmer Vernooij
Use start_write_group() / commit_write_group() mechanism when creating git SHA maps.
132
        self.map.commit_write_group()
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
133
        self.assertEquals(["myrevid"], list(self.map.revids()))
134
0.200.747 by Jelmer Vernooij
Add test for ShaMap.missing_revisions().
135
    def test_missing_revisions(self):
136
        self.map.start_write_group()
0.200.850 by Jelmer Vernooij
Fix tests.
137
        updater = self.cache.get_updater(Revision("myrevid"))
138
        c = self._get_test_commit()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
139
        updater.add_object(c, {"testament3-sha1": "testament"}, None)
0.200.850 by Jelmer Vernooij
Fix tests.
140
        updater.finish()
0.200.747 by Jelmer Vernooij
Add test for ShaMap.missing_revisions().
141
        self.map.commit_write_group()
142
        self.assertEquals(set(["lala", "bla"]),
143
            set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
144
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
145
146
class DictGitShaMapTests(TestCase,TestGitShaMap):
147
148
    def setUp(self):
0.200.280 by Jelmer Vernooij
Support bzr.dev.
149
        TestCase.setUp(self)
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
150
        self.cache = DictBzrGitCache()
151
        self.map = self.cache.idmap
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
152
153
0.200.850 by Jelmer Vernooij
Fix tests.
154
class SqliteGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
155
156
    def setUp(self):
0.200.850 by Jelmer Vernooij
Fix tests.
157
        TestCaseInTempDir.setUp(self)
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
158
        self.cache = SqliteBzrGitCache(os.path.join(self.test_dir, 'foo.db'))
159
        self.map = self.cache.idmap
0.200.262 by Jelmer Vernooij
Add tests for GitShaMap.
160
0.200.475 by Jelmer Vernooij
Add Tdb database backend.
161
162
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
163
164
    def setUp(self):
165
        TestCaseInTempDir.setUp(self)
166
        try:
0.200.1075 by Jelmer Vernooij
Fix compatibility with older versions of python-tdb.
167
            self.cache = TdbBzrGitCache(
168
                os.path.join(self.test_dir, 'foo.tdb').encode(osutils._fs_enc))
0.200.475 by Jelmer Vernooij
Add Tdb database backend.
169
        except ImportError:
170
            raise UnavailableFeature("Missing tdb")
0.200.849 by Jelmer Vernooij
Allow cache backends to decide when to add entries rather than adding once per commit.
171
        self.map = self.cache.idmap
0.254.1 by Jelmer Vernooij
Add trivial index-based sha map.
172
173
174
class IndexGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
175
176
    def setUp(self):
177
        TestCaseInTempDir.setUp(self)
0.254.48 by Jelmer Vernooij
Merge trunk
178
        transport = get_transport(self.test_dir)
0.200.952 by Jelmer Vernooij
Write git pack files rather than loose objects.
179
        IndexGitCacheFormat().initialize(transport)
0.254.48 by Jelmer Vernooij
Merge trunk
180
        self.cache = IndexBzrGitCache(transport)
0.254.46 by Jelmer Vernooij
Merge trunk.
181
        self.map = self.cache.idmap