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