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