/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.51 by Jelmer Vernooij
Fix copyright.
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
2
# -*- encoding: utf-8 -*-
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
3
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
8
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
13
#
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
18
from bzrlib.inventory import (
19
    InventoryDirectory,
20
    InventoryFile,
21
    )
22
0.200.264 by Jelmer Vernooij
Add more tests.
23
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
24
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
25
    Commit,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
26
    Tree,
0.200.264 by Jelmer Vernooij
Add more tests.
27
    )
28
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
29
from bzrlib.plugins.git import tests
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
30
from bzrlib.plugins.git.mapping import (
31
    BzrGitMappingv1,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
32
    directory_to_tree,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
33
    escape_file_id,
34
    unescape_file_id,
35
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
36
37
38
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
39
40
    def test_simple_git_to_bzr_revision_id(self):
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
41
        self.assertEqual("git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
42
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
43
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
44
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
45
46
    def test_simple_bzr_to_git_revision_id(self):
0.200.195 by Jelmer Vernooij
Return mapping in revision_id_bzr_to_foreign() as required by the interface.
47
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
48
                         BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
49
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
50
                            "git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
51
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
52
53
54
class FileidTests(tests.TestCase):
55
56
    def test_escape_space(self):
57
        self.assertEquals("bla_s", escape_file_id("bla "))
58
59
    def test_escape_underscore(self):
60
        self.assertEquals("bla__", escape_file_id("bla_"))
61
62
    def test_escape_underscore_space(self):
63
        self.assertEquals("bla___s", escape_file_id("bla_ "))
64
65
    def test_unescape_underscore(self):
66
        self.assertEquals("bla ", unescape_file_id("bla_s"))
67
68
    def test_unescape_underscore_space(self):
69
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
70
71
72
class TestImportCommit(tests.TestCase):
73
74
    def test_commit(self):
75
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
76
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
77
        c.message = "Some message"
78
        c.committer = "Committer"
79
        c.commit_time = 4
80
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
81
        c.commit_timezone = 60 * 5
82
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
83
        c.author = "Author"
0.252.1 by Jelmer Vernooij
Support storing revision id data.
84
        rev, file_ids = BzrGitMappingv1().import_commit(c)
0.200.264 by Jelmer Vernooij
Add more tests.
85
        self.assertEquals("Some message", rev.message)
86
        self.assertEquals("Committer", rev.committer)
87
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
88
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
89
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
90
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
91
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
92
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
93
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
94
    def test_explicit_encoding(self):
95
        c = Commit()
96
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
97
        c.message = "Some message"
98
        c.committer = "Committer"
99
        c.commit_time = 4
100
        c.author_time = 5
101
        c.commit_timezone = 60 * 5
102
        c.author_timezone = 60 * 3
103
        c.author = u"Authér".encode("iso8859-1")
104
        c.encoding = "iso8859-1"
0.252.1 by Jelmer Vernooij
Support storing revision id data.
105
        rev, file_ids = BzrGitMappingv1().import_commit(c)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
106
        self.assertEquals(u"Authér", rev.properties['author'])
107
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
108
        self.assertTrue("git-implicit-encoding" not in rev.properties)
109
110
    def test_implicit_encoding_fallback(self):
111
        c = Commit()
112
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
113
        c.message = "Some message"
114
        c.committer = "Committer"
115
        c.commit_time = 4
116
        c.author_time = 5
117
        c.commit_timezone = 60 * 5
118
        c.author_timezone = 60 * 3
119
        c.author = u"Authér".encode("latin1")
0.252.1 by Jelmer Vernooij
Support storing revision id data.
120
        rev, file_ids = BzrGitMappingv1().import_commit(c)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
121
        self.assertEquals(u"Authér", rev.properties['author'])
122
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
123
        self.assertTrue("git-explicit-encoding" not in rev.properties)
124
125
    def test_implicit_encoding_utf8(self):
126
        c = Commit()
127
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
128
        c.message = "Some message"
129
        c.committer = "Committer"
130
        c.commit_time = 4
131
        c.author_time = 5
132
        c.commit_timezone = 60 * 5
133
        c.author_timezone = 60 * 3
134
        c.author = u"Authér".encode("utf-8")
0.252.1 by Jelmer Vernooij
Support storing revision id data.
135
        rev, file_ids = BzrGitMappingv1().import_commit(c)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
136
        self.assertEquals(u"Authér", rev.properties['author'])
137
        self.assertTrue("git-explicit-encoding" not in rev.properties)
138
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
139
140
141
class RoundtripRevisionsFromGit(tests.TestCase):
142
143
    def setUp(self):
144
        super(RoundtripRevisionsFromGit, self).setUp()
145
        self.mapping = BzrGitMappingv1()
146
147
    def assertRoundtripTree(self, tree):
148
        raise NotImplementedError(self.assertRoundtripTree)
149
150
    def assertRoundtripBlob(self, blob):
151
        raise NotImplementedError(self.assertRoundtripBlob)
152
153
    def assertRoundtripCommit(self, commit1):
0.252.1 by Jelmer Vernooij
Support storing revision id data.
154
        rev, file_ids = self.mapping.import_commit(commit1)
155
        self.assertEquals(file_ids, {})
0.242.1 by Jelmer Vernooij
Add support for parsing hg-git metadata in the experimental mappings.
156
        commit2 = self.mapping.export_commit(rev, "12341212121212", None)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
157
        self.assertEquals(commit1.committer, commit2.committer)
158
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
159
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
160
        self.assertEquals(commit1.author, commit2.author)
161
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
162
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
163
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
164
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
165
166
    def test_commit(self):
167
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
168
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
169
        c.message = "Some message"
170
        c.committer = "Committer <Committer>"
171
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
172
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
173
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
174
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
175
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
176
        self.assertRoundtripCommit(c)
177
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
178
    def test_commit_zero_utc_timezone(self):
179
        c = Commit()
180
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
181
        c.message = "Some message"
182
        c.committer = "Committer <Committer>"
183
        c.commit_time = 4
184
        c.commit_timezone = 0
185
        c._commit_timezone_neg_utc = True
186
        c.author_time = 5
187
        c.author_timezone = 60 * 2
188
        c.author = "Author <author>"
189
        self.assertRoundtripCommit(c)
190
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
191
    def test_commit_encoding(self):
192
        c = Commit()
193
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
194
        c.message = "Some message"
195
        c.committer = "Committer <Committer>"
196
        c.encoding = 'iso8859-1'
197
        c.commit_time = 4
198
        c.commit_timezone = -60 * 3
199
        c.author_time = 5
200
        c.author_timezone = 60 * 2
201
        c.author = "Author <author>"
202
        self.assertRoundtripCommit(c)
203
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
204
205
class DirectoryToTreeTests(tests.TestCase):
206
207
    def test_empty(self):
208
        ie = InventoryDirectory('foo', 'foo', 'foo')
209
        t = directory_to_tree(ie, None, {})
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
210
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
211
212
    def test_empty_dir(self):
213
        ie = InventoryDirectory('foo', 'foo', 'foo')
214
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
215
        ie.children['bar'] = child_ie
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
216
        t = directory_to_tree(ie, lambda x: None, {})
217
        self.assertEquals(None, t)
218
219
    def test_empty_root(self):
220
        ie = InventoryDirectory('foo', 'foo', None)
221
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
222
        ie.children['bar'] = child_ie
223
        t = directory_to_tree(ie, lambda x: None, {})
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
224
        self.assertEquals(Tree(), t)
225
226
    def test_with_file(self):
227
        ie = InventoryDirectory('foo', 'foo', 'foo')
228
        child_ie = InventoryFile('bar', 'bar', 'bar')
229
        ie.children['bar'] = child_ie
230
        b = Blob.from_string("bla")
231
        t1 = directory_to_tree(ie, lambda x: b.id, {})
232
        t2 = Tree()
233
        t2.add(0100644, "bar", b.id)
234
        self.assertEquals(t1, t2)