/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) 2007-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.201.1 by Jelmer Vernooij
Add very small initial testsuite.
17
0.358.3 by Jelmer Vernooij
Enable absolute import.
18
"""Tests for mapping."""
19
20
from __future__ import absolute_import
21
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
22
from ....bzr.inventory import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
23
    InventoryDirectory,
24
    InventoryFile,
25
    )
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
26
from ....revision import (
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
27
    Revision,
28
    )
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
29
0.200.264 by Jelmer Vernooij
Add more tests.
30
from dulwich.objects import (
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
31
    Blob,
0.200.264 by Jelmer Vernooij
Add more tests.
32
    Commit,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
33
    Tree,
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
34
    parse_timezone,
0.200.264 by Jelmer Vernooij
Add more tests.
35
    )
36
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
37
from .. import tests
38
from ..errors import UnknownCommitExtra
39
from ..mapping import (
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
40
    BzrGitMappingv1,
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
41
    directory_to_tree,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
42
    escape_file_id,
0.402.1 by Jelmer Vernooij
Improve identifier handling.
43
    fix_person_identifier,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
44
    unescape_file_id,
45
    )
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
46
47
48
class TestRevidConversionV1(tests.TestCase):
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
49
50
    def test_simple_git_to_bzr_revision_id(self):
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
51
        self.assertEqual("git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
52
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
53
                         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.
54
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
55
56
    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.
57
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
58
                         BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
59
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
60
                            "git-v1:"
0.204.1 by James Westby
Fix id tests to match new revid prefix.
61
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
62
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
63
    def test_is_control_file(self):
64
        mapping = BzrGitMappingv1()
0.200.920 by Jelmer Vernooij
Fix some more tests.
65
        if mapping.roundtripping:
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
66
            self.assertTrue(mapping.is_special_file(".bzrdummy"))
67
            self.assertTrue(mapping.is_special_file(".bzrfileids"))
68
        self.assertFalse(mapping.is_special_file(".bzrfoo"))
0.252.26 by Jelmer Vernooij
Add is_control_file method to BzrGitMapping.
69
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
70
    def test_generate_file_id(self):
71
        mapping = BzrGitMappingv1()
72
        self.assertIsInstance(mapping.generate_file_id("la"), str)
73
        self.assertIsInstance(mapping.generate_file_id(u"é"), str)
74
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
75
76
class FileidTests(tests.TestCase):
77
78
    def test_escape_space(self):
79
        self.assertEquals("bla_s", escape_file_id("bla "))
80
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
81
    def test_escape_control_l(self):
82
        self.assertEquals("bla_c", escape_file_id("bla\x0c"))
83
84
    def test_unescape_control_l(self):
85
        self.assertEquals("bla\x0c", unescape_file_id("bla_c"))
86
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
87
    def test_escape_underscore(self):
88
        self.assertEquals("bla__", escape_file_id("bla_"))
89
90
    def test_escape_underscore_space(self):
91
        self.assertEquals("bla___s", escape_file_id("bla_ "))
92
93
    def test_unescape_underscore(self):
94
        self.assertEquals("bla ", unescape_file_id("bla_s"))
95
96
    def test_unescape_underscore_space(self):
97
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
0.200.264 by Jelmer Vernooij
Add more tests.
98
99
100
class TestImportCommit(tests.TestCase):
101
102
    def test_commit(self):
103
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
104
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
105
        c.message = "Some message"
106
        c.committer = "Committer"
107
        c.commit_time = 4
108
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
109
        c.commit_timezone = 60 * 5
110
        c.author_timezone = 60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
111
        c.author = "Author"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
112
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
113
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
114
            mapping.revision_id_foreign_to_bzr)
115
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
116
        self.assertEquals({}, verifiers)
0.200.264 by Jelmer Vernooij
Add more tests.
117
        self.assertEquals("Some message", rev.message)
118
        self.assertEquals("Committer", rev.committer)
119
        self.assertEquals("Author", rev.properties['author'])
0.200.368 by Jelmer Vernooij
Cope with more granular timezones.
120
        self.assertEquals(300, rev.timezone)
0.200.264 by Jelmer Vernooij
Add more tests.
121
        self.assertEquals((), rev.parent_ids)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
122
        self.assertEquals("5", rev.properties['author-timestamp'])
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
123
        self.assertEquals("180", rev.properties['author-timezone'])
0.200.264 by Jelmer Vernooij
Add more tests.
124
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
125
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
126
    def test_explicit_encoding(self):
127
        c = Commit()
128
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
129
        c.message = "Some message"
130
        c.committer = "Committer"
131
        c.commit_time = 4
132
        c.author_time = 5
133
        c.commit_timezone = 60 * 5
134
        c.author_timezone = 60 * 3
135
        c.author = u"Authér".encode("iso8859-1")
136
        c.encoding = "iso8859-1"
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
137
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
138
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
139
            mapping.revision_id_foreign_to_bzr)
140
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
141
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
142
        self.assertEquals(u"Authér", rev.properties['author'])
143
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
144
        self.assertTrue("git-implicit-encoding" not in rev.properties)
145
146
    def test_implicit_encoding_fallback(self):
147
        c = Commit()
148
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
149
        c.message = "Some message"
150
        c.committer = "Committer"
151
        c.commit_time = 4
152
        c.author_time = 5
153
        c.commit_timezone = 60 * 5
154
        c.author_timezone = 60 * 3
155
        c.author = u"Authér".encode("latin1")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
156
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
157
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
158
            mapping.revision_id_foreign_to_bzr)
159
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
160
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
161
        self.assertEquals(u"Authér", rev.properties['author'])
162
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
163
        self.assertTrue("git-explicit-encoding" not in rev.properties)
164
165
    def test_implicit_encoding_utf8(self):
166
        c = Commit()
167
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
168
        c.message = "Some message"
169
        c.committer = "Committer"
170
        c.commit_time = 4
171
        c.author_time = 5
172
        c.commit_timezone = 60 * 5
173
        c.author_timezone = 60 * 3
174
        c.author = u"Authér".encode("utf-8")
0.252.44 by Jelmer Vernooij
Properly look up Bazaar revision ids for revision parents in case they are round-tripped.
175
        mapping = BzrGitMappingv1()
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
176
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
177
            mapping.revision_id_foreign_to_bzr)
178
        self.assertEquals(None, roundtrip_revid)
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
179
        self.assertEquals({}, verifiers)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
180
        self.assertEquals(u"Authér", rev.properties['author'])
181
        self.assertTrue("git-explicit-encoding" not in rev.properties)
182
        self.assertTrue("git-implicit-encoding" not in rev.properties)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
183
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
184
    def test_unknown_extra(self):
185
        c = Commit()
186
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
187
        c.message = "Some message"
188
        c.committer = "Committer"
189
        c.commit_time = 4
190
        c.author_time = 5
191
        c.commit_timezone = 60 * 5
192
        c.author_timezone = 60 * 3
193
        c.author = "Author"
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
194
        c._extra.append(("iamextra", "foo"))
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
195
        mapping = BzrGitMappingv1()
196
        self.assertRaises(UnknownCommitExtra, mapping.import_commit, c,
197
            mapping.revision_id_foreign_to_bzr)
198
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
199
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
200
class RoundtripRevisionsFromBazaar(tests.TestCase):
201
202
    def setUp(self):
203
        super(RoundtripRevisionsFromBazaar, self).setUp()
204
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
205
        self._parent_map = {}
206
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
207
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
208
    def assertRoundtripRevision(self, orig_rev):
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
209
        commit = self.mapping.export_commit(orig_rev, "mysha",
0.200.1023 by Jelmer Vernooij
Set and verify testament.
210
            self._lookup_parent, True, "testamentsha")
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
211
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
212
            commit, self.mapping.revision_id_foreign_to_bzr)
213
        self.assertEquals(rev.revision_id,
214
            self.mapping.revision_id_foreign_to_bzr(commit.id))
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
215
        if self.mapping.roundtripping:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
216
            self.assertEquals({"testament3-sha1": "testamentsha"} , verifiers)
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
217
            self.assertEquals(orig_rev.revision_id, roundtrip_revid)
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
218
            self.assertEquals(orig_rev.properties, rev.properties)
219
            self.assertEquals(orig_rev.committer, rev.committer)
220
            self.assertEquals(orig_rev.timestamp, rev.timestamp)
221
            self.assertEquals(orig_rev.timezone, rev.timezone)
222
            self.assertEquals(orig_rev.message, rev.message)
223
            self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
0.200.1023 by Jelmer Vernooij
Set and verify testament.
224
        else:
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
225
            self.assertEquals({}, verifiers)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
226
227
    def test_simple_commit(self):
228
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
229
        r.message = "MyCommitMessage"
230
        r.parent_ids = []
231
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
232
        r.timestamp = 453543543
233
        r.timezone = 0
234
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
235
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
236
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
237
    def test_revision_id(self):
238
        r = Revision("myrevid")
239
        r.message = "MyCommitMessage"
240
        r.parent_ids = []
241
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
242
        r.timestamp = 453543543
243
        r.timezone = 0
244
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
245
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
246
247
    def test_ghost_parent(self):
248
        r = Revision("myrevid")
249
        r.message = "MyCommitMessage"
250
        r.parent_ids = ["iamaghost"]
251
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
252
        r.timestamp = 453543543
253
        r.timezone = 0
254
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
255
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
256
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
257
    def test_custom_property(self):
258
        r = Revision("myrevid")
259
        r.message = "MyCommitMessage"
260
        r.parent_ids = []
261
        r.properties = {"fool": "bar"}
262
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
263
        r.timestamp = 453543543
264
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
265
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
266
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
267
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
268
class RoundtripRevisionsFromGit(tests.TestCase):
269
270
    def setUp(self):
271
        super(RoundtripRevisionsFromGit, self).setUp()
272
        self.mapping = BzrGitMappingv1()
273
274
    def assertRoundtripTree(self, tree):
275
        raise NotImplementedError(self.assertRoundtripTree)
276
277
    def assertRoundtripBlob(self, blob):
278
        raise NotImplementedError(self.assertRoundtripBlob)
279
280
    def assertRoundtripCommit(self, commit1):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
281
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
0.200.1021 by Jelmer Vernooij
Put testament sha1 in revisions.
282
            commit1, self.mapping.revision_id_foreign_to_bzr)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
283
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
0.200.1023 by Jelmer Vernooij
Set and verify testament.
284
            True, None)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
285
        self.assertEquals(commit1.committer, commit2.committer)
286
        self.assertEquals(commit1.commit_time, commit2.commit_time)
0.200.362 by Jelmer Vernooij
Fix tests.
287
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
288
        self.assertEquals(commit1.author, commit2.author)
289
        self.assertEquals(commit1.author_time, commit2.author_time)
0.200.362 by Jelmer Vernooij
Fix tests.
290
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
291
        self.assertEquals(commit1.message, commit2.message)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
292
        self.assertEquals(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
293
294
    def test_commit(self):
295
        c = Commit()
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
296
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
297
        c.message = "Some message"
298
        c.committer = "Committer <Committer>"
299
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
300
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
301
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
302
        c.author_timezone = 60 * 2
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
303
        c.author = "Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
304
        self.assertRoundtripCommit(c)
305
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
306
    def test_commit_double_negative_timezone(self):
307
        c = Commit()
308
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
309
        c.message = "Some message"
310
        c.committer = "Committer <Committer>"
311
        c.commit_time = 4
312
        (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone("--700")
313
        c.author_time = 5
314
        c.author_timezone = 60 * 2
315
        c.author = "Author <author>"
316
        self.assertRoundtripCommit(c)
317
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
318
    def test_commit_zero_utc_timezone(self):
319
        c = Commit()
320
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
321
        c.message = "Some message"
322
        c.committer = "Committer <Committer>"
323
        c.commit_time = 4
324
        c.commit_timezone = 0
325
        c._commit_timezone_neg_utc = True
326
        c.author_time = 5
327
        c.author_timezone = 60 * 2
328
        c.author = "Author <author>"
329
        self.assertRoundtripCommit(c)
330
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
331
    def test_commit_encoding(self):
332
        c = Commit()
333
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
334
        c.message = "Some message"
335
        c.committer = "Committer <Committer>"
336
        c.encoding = 'iso8859-1'
337
        c.commit_time = 4
338
        c.commit_timezone = -60 * 3
339
        c.author_time = 5
340
        c.author_timezone = 60 * 2
341
        c.author = "Author <author>"
342
        self.assertRoundtripCommit(c)
343
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
344
    def test_commit_extra(self):
345
        c = Commit()
346
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
347
        c.message = "Some message"
348
        c.committer = "Committer <Committer>"
349
        c.commit_time = 4
350
        c.commit_timezone = -60 * 3
351
        c.author_time = 5
352
        c.author_timezone = 60 * 2
353
        c.author = "Author <author>"
354
        c._extra = [("HG:rename-source", "hg")]
355
        self.assertRoundtripCommit(c)
356
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
357
358
class DirectoryToTreeTests(tests.TestCase):
359
360
    def test_empty(self):
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
361
        t = directory_to_tree({}, None, {}, None, allow_empty=False)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
362
        self.assertEquals(None, t)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
363
364
    def test_empty_dir(self):
365
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
366
        children = {'bar': child_ie}
367
        t = directory_to_tree(children, lambda x: None, {}, None,
368
                allow_empty=False)
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
369
        self.assertEquals(None, t)
370
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
371
    def test_empty_dir_dummy_files(self):
372
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
373
        children = {'bar':child_ie}
374
        t = directory_to_tree(children, lambda x: None, {}, ".mydummy",
375
                allow_empty=False)
0.252.30 by Jelmer Vernooij
Support creating dummy files for empty directories.
376
        self.assertTrue(".mydummy" in t)
377
0.200.589 by Jelmer Vernooij
Fix handling of empty trees.
378
    def test_empty_root(self):
379
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
380
        children = {'bar': child_ie}
381
        t = directory_to_tree(children, lambda x: None, {}, None,
382
                allow_empty=True)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
383
        self.assertEquals(Tree(), t)
384
385
    def test_with_file(self):
386
        child_ie = InventoryFile('bar', 'bar', 'bar')
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
387
        children = {"bar": child_ie}
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
388
        b = Blob.from_string("bla")
0.275.4 by Jelmer Vernooij
Pass children list to directory_to_tree .
389
        t1 = directory_to_tree(children, lambda x: b.id, {}, None,
390
                allow_empty=False)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
391
        t2 = Tree()
0.200.1152 by Jelmer Vernooij
Require dulwich 0.7.1.
392
        t2.add("bar", 0100644, b.id)
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
393
        self.assertEquals(t1, t2)
0.402.1 by Jelmer Vernooij
Improve identifier handling.
394
395
396
class FixPersonIdentifierTests(tests.TestCase):
397
398
    def test_valid(self):
399
        self.assertEqual("foo <bar@blah.nl>",
400
                         fix_person_identifier("foo <bar@blah.nl>"))
401
        self.assertEqual("bar@blah.nl <bar@blah.nl>",
402
                         fix_person_identifier("bar@blah.nl"))
403
404
    def test_fix(self):
405
        self.assertEqual("person <bar@blah.nl>",
406
                         fix_person_identifier("somebody <person <bar@blah.nl>>"))
407
        self.assertEqual("person <bar@blah.nl>",
408
                         fix_person_identifier("person<bar@blah.nl>"))
409
        self.assertRaises(ValueError,
410
                         fix_person_identifier, "person >bar@blah.nl<")