/brz/remove-bazaar

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