/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
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
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.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
30
    parse_timezone,
0.200.264 by Jelmer Vernooij
Add more tests.
31
    )
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
32
from dulwich.tests.utils import (
33
    make_object,
34
    )
0.200.264 by Jelmer Vernooij
Add more tests.
35
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
36
from .. import tests
37
from ..mapping import (
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
38
    BzrGitMappingv1,
39
    escape_file_id,
0.402.1 by Jelmer Vernooij
Improve identifier handling.
40
    fix_person_identifier,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
41
    unescape_file_id,
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
42
    UnknownCommitExtra,
43
    UnknownMercurialCommitExtra,
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
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):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
50
        self.assertEqual(b"git-v1:"
51
                         b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
52
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
7143.15.2 by Jelmer Vernooij
Run autopep8.
53
                             b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
0.200.18 by John Arbash Meinel
Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.
54
55
    def test_simple_bzr_to_git_revision_id(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
56
        self.assertEqual((b"c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
7143.15.2 by Jelmer Vernooij
Run autopep8.
57
                          BzrGitMappingv1()),
0.200.190 by Jelmer Vernooij
Bless current mapping as v1.
58
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
7143.15.2 by Jelmer Vernooij
Run autopep8.
59
            b"git-v1:"
60
            b"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()
7018.3.2 by Jelmer Vernooij
Fix some git tests.
71
        self.assertIsInstance(mapping.generate_file_id("la"), bytes)
72
        self.assertIsInstance(mapping.generate_file_id(u"é"), bytes)
0.200.973 by Jelmer Vernooij
Add tests for generate_file_id.
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):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
78
        self.assertEqual(b"bla_s", escape_file_id(b"bla "))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
79
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
80
    def test_escape_control_l(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
81
        self.assertEqual(b"bla_c", escape_file_id(b"bla\x0c"))
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
82
83
    def test_unescape_control_l(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
84
        self.assertEqual(b"bla\x0c", unescape_file_id(b"bla_c"))
0.200.1419 by Jelmer Vernooij
Escape/unescape ^L characters.
85
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
86
    def test_escape_underscore(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
87
        self.assertEqual(b"bla__", escape_file_id(b"bla_"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
88
89
    def test_escape_underscore_space(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
90
        self.assertEqual(b"bla___s", escape_file_id(b"bla_ "))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
91
92
    def test_unescape_underscore(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
93
        self.assertEqual(b"bla ", unescape_file_id(b"bla_s"))
0.200.258 by Jelmer Vernooij
add tests for file id escape/unescape.
94
95
    def test_unescape_underscore_space(self):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
96
        self.assertEqual(b"bla _", unescape_file_id(b"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()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
103
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
104
        c.message = b"Some message"
105
        c.committer = b"Committer"
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
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
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
110
        c.author = b"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()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
112
        rev, roundtrip_revid, verifiers = mapping.import_commit(
113
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
114
        self.assertEqual(None, roundtrip_revid)
115
        self.assertEqual({}, verifiers)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
116
        self.assertEqual(u"Some message", rev.message)
117
        self.assertEqual(u"Committer", rev.committer)
118
        self.assertEqual(u"Author", rev.properties[u'author'])
6964.2.3 by Jelmer Vernooij
Review comments.
119
        self.assertEqual(300, rev.timezone)
7096.3.2 by Jelmer Vernooij
Fix some git tests.
120
        self.assertEqual([], rev.parent_ids)
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
121
        self.assertEqual("5", rev.properties[u'author-timestamp'])
122
        self.assertEqual("180", rev.properties[u'author-timezone'])
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
123
        self.assertEqual(b"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()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
127
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
128
        c.message = b"Some message"
129
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
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")
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
135
        c.encoding = b"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()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
137
        rev, roundtrip_revid, verifiers = mapping.import_commit(
138
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
139
        self.assertEqual(None, roundtrip_revid)
140
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
141
        self.assertEqual(u"Authér", rev.properties[u'author'])
142
        self.assertEqual("iso8859-1", rev.properties[u"git-explicit-encoding"])
143
        self.assertTrue(u"git-implicit-encoding" not in rev.properties)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
144
145
    def test_implicit_encoding_fallback(self):
146
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
147
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
148
        c.message = b"Some message"
149
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
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()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
156
        rev, roundtrip_revid, verifiers = mapping.import_commit(
157
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
158
        self.assertEqual(None, roundtrip_revid)
159
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
160
        self.assertEqual(u"Authér", rev.properties[u'author'])
161
        self.assertEqual("latin1", rev.properties[u"git-implicit-encoding"])
162
        self.assertTrue(u"git-explicit-encoding" not in rev.properties)
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
163
164
    def test_implicit_encoding_utf8(self):
165
        c = Commit()
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
166
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
167
        c.message = b"Some message"
168
        c.committer = b"Committer"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
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()
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
175
        rev, roundtrip_revid, verifiers = mapping.import_commit(
176
            c, mapping.revision_id_foreign_to_bzr)
6964.2.3 by Jelmer Vernooij
Review comments.
177
        self.assertEqual(None, roundtrip_revid)
178
        self.assertEqual({}, verifiers)
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
179
        self.assertEqual(u"Authér", rev.properties[u'author'])
6973.13.2 by Jelmer Vernooij
Fix some more tests.
180
        self.assertTrue(u"git-explicit-encoding" not in rev.properties)
181
        self.assertTrue(u"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()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
185
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
186
        c.message = b"Some message"
187
        c.committer = b"Committer"
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
188
        c.commit_time = 4
189
        c.author_time = 5
190
        c.commit_timezone = 60 * 5
191
        c.author_timezone = 60 * 3
6973.13.2 by Jelmer Vernooij
Fix some more tests.
192
        c.author = b"Author"
193
        c._extra.append((b"iamextra", b"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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
196
                          mapping.revision_id_foreign_to_bzr)
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
197
        mapping.import_commit(c, mapping.revision_id_foreign_to_bzr, strict=False)
0.200.1598 by Jelmer Vernooij
Print proper error when unknown fields are encountered.
198
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
199
    def test_mergetag(self):
200
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
201
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
202
        c.message = b"Some message"
203
        c.committer = b"Committer"
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
204
        c.commit_time = 4
205
        c.author_time = 5
206
        c.commit_timezone = 60 * 5
207
        c.author_timezone = 60 * 3
6973.13.2 by Jelmer Vernooij
Fix some more tests.
208
        c.author = b"Author"
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
209
        tag = make_object(Tag,
7143.15.2 by Jelmer Vernooij
Run autopep8.
210
                          tagger=b'Jelmer Vernooij <jelmer@samba.org>',
211
                          name=b'0.1', message=None,
212
                          object=(
213
                              Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
214
                          tag_time=423423423, tag_timezone=0)
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
215
        c.mergetag = [tag]
216
        mapping = BzrGitMappingv1()
217
        rev, roundtrip_revid, verifiers = mapping.import_commit(
7143.15.2 by Jelmer Vernooij
Run autopep8.
218
            c, mapping.revision_id_foreign_to_bzr)
219
        self.assertEqual(
220
            rev.properties[u'git-mergetag-0'], tag.as_raw_string())
0.413.2 by Jelmer Vernooij
Add support for the mergetag property in git.
221
7240.10.1 by Jelmer Vernooij
Properly handle exceptions about hg extra fields.
222
    def test_unknown_hg_fields(self):
223
        c = Commit()
224
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
225
        c.message = b"Some message"
226
        c.committer = b"Committer"
227
        c.commit_time = 4
228
        c.author_time = 5
229
        c.commit_timezone = 60 * 5
230
        c.author_timezone = 60 * 3
231
        c.author = b"Author"
232
        c._extra = [(b"HG:extra", b"bla:Foo")]
233
        mapping = BzrGitMappingv1()
234
        self.assertRaises(
235
            UnknownMercurialCommitExtra,
236
            mapping.import_commit, c, mapping.revision_id_foreign_to_bzr)
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
237
        mapping.import_commit(
238
            c, mapping.revision_id_foreign_to_bzr, strict=False)
7268.1.2 by Jelmer Vernooij
Allow access to native git repositories, ignoring unknown hg fields.
239
        self.assertEqual(
240
            mapping.revision_id_foreign_to_bzr(c.id),
241
            mapping.get_revision_id(c))
7240.10.1 by Jelmer Vernooij
Properly handle exceptions about hg extra fields.
242
7290.21.1 by Jelmer Vernooij
Cope with utf-8 invalid characters in commit messages when scanning for revision ids.
243
    def test_invalid_utf8(self):
244
        c = Commit()
245
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
246
        c.message = b"Some message \xc1"
247
        c.committer = b"Committer"
248
        c.commit_time = 4
249
        c.author_time = 5
250
        c.commit_timezone = 60 * 5
251
        c.author_timezone = 60 * 3
252
        c.author = b"Author"
253
        mapping = BzrGitMappingv1()
254
        self.assertEqual(
255
            mapping.revision_id_foreign_to_bzr(c.id),
256
            mapping.get_revision_id(c))
257
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
258
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
259
class RoundtripRevisionsFromBazaar(tests.TestCase):
260
261
    def setUp(self):
262
        super(RoundtripRevisionsFromBazaar, self).setUp()
263
        self.mapping = BzrGitMappingv1()
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
264
        self._parent_map = {}
265
        self._lookup_parent = self._parent_map.__getitem__
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
266
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
267
    def assertRoundtripRevision(self, orig_rev):
7018.3.5 by Jelmer Vernooij
Fix remaining tests.
268
        commit = self.mapping.export_commit(orig_rev, b"mysha",
7143.15.2 by Jelmer Vernooij
Run autopep8.
269
                                            self._lookup_parent, True, b"testamentsha")
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
270
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
271
            commit, self.mapping.revision_id_foreign_to_bzr, strict=True)
6964.2.3 by Jelmer Vernooij
Review comments.
272
        self.assertEqual(rev.revision_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
273
                         self.mapping.revision_id_foreign_to_bzr(commit.id))
0.200.912 by Jelmer Vernooij
Merge roundtrip support.
274
        if self.mapping.roundtripping:
7143.15.2 by Jelmer Vernooij
Run autopep8.
275
            self.assertEqual({"testament3-sha1": b"testamentsha"}, verifiers)
6964.2.3 by Jelmer Vernooij
Review comments.
276
            self.assertEqual(orig_rev.revision_id, roundtrip_revid)
277
            self.assertEqual(orig_rev.properties, rev.properties)
278
            self.assertEqual(orig_rev.committer, rev.committer)
279
            self.assertEqual(orig_rev.timestamp, rev.timestamp)
280
            self.assertEqual(orig_rev.timezone, rev.timezone)
281
            self.assertEqual(orig_rev.message, rev.message)
282
            self.assertEqual(list(orig_rev.parent_ids), list(rev.parent_ids))
0.200.1023 by Jelmer Vernooij
Set and verify testament.
283
        else:
6964.2.3 by Jelmer Vernooij
Review comments.
284
            self.assertEqual({}, verifiers)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
285
286
    def test_simple_commit(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
287
        r = Revision(self.mapping.revision_id_foreign_to_bzr(
288
            b"edf99e6c56495c620f20d5dacff9859ff7119261"))
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
289
        r.message = "MyCommitMessage"
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
290
        r.parent_ids = []
291
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
292
        r.timestamp = 453543543
293
        r.timezone = 0
294
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
295
        self.assertRoundtripRevision(r)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
296
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
297
    def test_revision_id(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
298
        r = Revision(b"myrevid")
7018.3.7 by Jelmer Vernooij
Fix remaining git tests.
299
        r.message = "MyCommitMessage"
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
300
        r.parent_ids = []
301
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
302
        r.timestamp = 453543543
303
        r.timezone = 0
304
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
305
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
306
307
    def test_ghost_parent(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
308
        r = Revision(b"myrevid")
309
        r.message = u"MyCommitMessage"
310
        r.parent_ids = [b"iamaghost"]
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
311
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
312
        r.timestamp = 453543543
313
        r.timezone = 0
314
        r.properties = {}
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
315
        self.assertRoundtripRevision(r)
0.252.8 by Jelmer Vernooij
Support ghost revisions while roundtripping.
316
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
317
    def test_custom_property(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
318
        r = Revision(b"myrevid")
319
        r.message = u"MyCommitMessage"
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
320
        r.parent_ids = []
6973.13.2 by Jelmer Vernooij
Fix some more tests.
321
        r.properties = {u"fool": "bar"}
0.252.10 by Jelmer Vernooij
Support roundtripping custom revision properties.
322
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
323
        r.timestamp = 453543543
324
        r.timezone = 0
0.252.22 by Jelmer Vernooij
Fix file id map (de)serialization.
325
        self.assertRoundtripRevision(r)
0.252.16 by Jelmer Vernooij
make sure file ids are roundtripped properly.
326
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
327
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
328
class RoundtripRevisionsFromGit(tests.TestCase):
329
330
    def setUp(self):
331
        super(RoundtripRevisionsFromGit, self).setUp()
332
        self.mapping = BzrGitMappingv1()
333
334
    def assertRoundtripTree(self, tree):
335
        raise NotImplementedError(self.assertRoundtripTree)
336
337
    def assertRoundtripBlob(self, blob):
338
        raise NotImplementedError(self.assertRoundtripBlob)
339
340
    def assertRoundtripCommit(self, commit1):
0.200.1029 by Jelmer Vernooij
Use dictionary with verifiers rather than requiring testament3-sha1 everywhere.
341
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
7410.2.1 by Jelmer Vernooij
Allow unknown extras in git commits when just inspecting revisions, rather than importing.
342
            commit1, self.mapping.revision_id_foreign_to_bzr, strict=True)
0.252.7 by Jelmer Vernooij
Add basic test for roundtripping from Bazaar.
343
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
344
                                             True, None)
6964.2.3 by Jelmer Vernooij
Review comments.
345
        self.assertEqual(commit1.committer, commit2.committer)
346
        self.assertEqual(commit1.commit_time, commit2.commit_time)
347
        self.assertEqual(commit1.commit_timezone, commit2.commit_timezone)
348
        self.assertEqual(commit1.author, commit2.author)
349
        self.assertEqual(commit1.author_time, commit2.author_time)
350
        self.assertEqual(commit1.author_timezone, commit2.author_timezone)
351
        self.assertEqual(commit1.message, commit2.message)
352
        self.assertEqual(commit1.encoding, commit2.encoding)
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
353
354
    def test_commit(self):
355
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
356
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
357
        c.message = b"Some message"
358
        c.committer = b"Committer <Committer>"
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
359
        c.commit_time = 4
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
360
        c.commit_timezone = -60 * 3
0.200.416 by Jelmer Vernooij
Use public properties to set git objects values.
361
        c.author_time = 5
0.200.440 by Jelmer Vernooij
Remove silly mapping of timezones; dulwich uses offsets now as well.
362
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
363
        c.author = b"Author <author>"
0.200.351 by Jelmer Vernooij
Add roundtrip tests.
364
        self.assertRoundtripCommit(c)
365
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
366
    def test_commit_double_negative_timezone(self):
367
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
368
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
369
        c.message = b"Some message"
370
        c.committer = b"Committer <Committer>"
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
371
        c.commit_time = 4
7018.3.2 by Jelmer Vernooij
Fix some git tests.
372
        (c.commit_timezone, c._commit_timezone_neg_utc) = parse_timezone(b"--700")
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
373
        c.author_time = 5
374
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
375
        c.author = b"Author <author>"
0.200.1589 by Jelmer Vernooij
Add test to make sure that certain invalid timezones are roundtripped correctly.
376
        self.assertRoundtripCommit(c)
377
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
378
    def test_commit_zero_utc_timezone(self):
379
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
380
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
381
        c.message = b"Some message"
382
        c.committer = b"Committer <Committer>"
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
383
        c.commit_time = 4
384
        c.commit_timezone = 0
385
        c._commit_timezone_neg_utc = True
386
        c.author_time = 5
387
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
388
        c.author = b"Author <author>"
0.200.884 by Jelmer Vernooij
Cope with -0000 as timezone in Git commits.
389
        self.assertRoundtripCommit(c)
390
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
391
    def test_commit_encoding(self):
392
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
393
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
394
        c.message = b"Some message"
395
        c.committer = b"Committer <Committer>"
396
        c.encoding = b'iso8859-1'
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
397
        c.commit_time = 4
398
        c.commit_timezone = -60 * 3
399
        c.author_time = 5
400
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
401
        c.author = b"Author <author>"
0.200.727 by Jelmer Vernooij
Cope with different encodings better, rather than just stripping out
402
        self.assertRoundtripCommit(c)
403
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
404
    def test_commit_extra(self):
405
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
406
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
407
        c.message = b"Some message"
408
        c.committer = b"Committer <Committer>"
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
409
        c.commit_time = 4
410
        c.commit_timezone = -60 * 3
411
        c.author_time = 5
412
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
413
        c.author = b"Author <author>"
414
        c._extra = [(b"HG:rename-source", b"hg")]
0.200.1639 by Jelmer Vernooij
Properly roundtrip HG:rename-source fields.
415
        self.assertRoundtripCommit(c)
416
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
417
    def test_commit_mergetag(self):
418
        c = Commit()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
419
        c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
420
        c.message = b"Some message"
421
        c.committer = b"Committer <Committer>"
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
422
        c.commit_time = 4
423
        c.commit_timezone = -60 * 3
424
        c.author_time = 5
425
        c.author_timezone = 60 * 2
6973.13.2 by Jelmer Vernooij
Fix some more tests.
426
        c.author = b"Author <author>"
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
427
        tag = make_object(Tag,
7143.15.2 by Jelmer Vernooij
Run autopep8.
428
                          tagger=b'Jelmer Vernooij <jelmer@samba.org>',
429
                          name=b'0.1', message=None,
430
                          object=(
431
                              Blob, b'd80c186a03f423a81b39df39dc87fd269736ca86'),
432
                          tag_time=423423423, tag_timezone=0)
0.414.2 by Jelmer Vernooij
Fix mergetag roundtripping.
433
        c.mergetag = [tag]
434
        self.assertRoundtripCommit(c)
435
0.200.588 by Jelmer Vernooij
Cope with empty directories that are not allowed in git.
436
0.402.1 by Jelmer Vernooij
Improve identifier handling.
437
class FixPersonIdentifierTests(tests.TestCase):
438
439
    def test_valid(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
440
        self.assertEqual(b"foo <bar@blah.nl>",
441
                         fix_person_identifier(b"foo <bar@blah.nl>"))
442
        self.assertEqual(b"bar@blah.nl <bar@blah.nl>",
443
                         fix_person_identifier(b"bar@blah.nl"))
0.402.1 by Jelmer Vernooij
Improve identifier handling.
444
445
    def test_fix(self):
6973.13.2 by Jelmer Vernooij
Fix some more tests.
446
        self.assertEqual(b"person <bar@blah.nl>",
447
                         fix_person_identifier(b"somebody <person <bar@blah.nl>>"))
448
        self.assertEqual(b"person <bar@blah.nl>",
449
                         fix_person_identifier(b"person<bar@blah.nl>"))
0.402.1 by Jelmer Vernooij
Improve identifier handling.
450
        self.assertRaises(ValueError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
451
                          fix_person_identifier, b"person >bar@blah.nl<")