110
92
self.assertEquals("180", rev.properties['author-timezone'])
111
93
self.assertEquals("git-v1:" + c.id, rev.revision_id)
113
def test_explicit_encoding(self):
115
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
116
c.message = "Some message"
117
c.committer = "Committer"
120
c.commit_timezone = 60 * 5
121
c.author_timezone = 60 * 3
122
c.author = u"Authér".encode("iso8859-1")
123
c.encoding = "iso8859-1"
124
mapping = BzrGitMappingv1()
125
rev, roundtrip_revid, verifiers = mapping.import_commit(c,
126
mapping.revision_id_foreign_to_bzr)
127
self.assertEquals(None, roundtrip_revid)
128
self.assertEquals({}, verifiers)
129
self.assertEquals(u"Authér", rev.properties['author'])
130
self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
131
self.assertTrue("git-implicit-encoding" not in rev.properties)
133
def test_implicit_encoding_fallback(self):
135
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
136
c.message = "Some message"
137
c.committer = "Committer"
140
c.commit_timezone = 60 * 5
141
c.author_timezone = 60 * 3
142
c.author = u"Authér".encode("latin1")
143
mapping = BzrGitMappingv1()
144
rev, roundtrip_revid, verifiers = mapping.import_commit(c,
145
mapping.revision_id_foreign_to_bzr)
146
self.assertEquals(None, roundtrip_revid)
147
self.assertEquals({}, verifiers)
148
self.assertEquals(u"Authér", rev.properties['author'])
149
self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
150
self.assertTrue("git-explicit-encoding" not in rev.properties)
152
def test_implicit_encoding_utf8(self):
154
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
155
c.message = "Some message"
156
c.committer = "Committer"
159
c.commit_timezone = 60 * 5
160
c.author_timezone = 60 * 3
161
c.author = u"Authér".encode("utf-8")
162
mapping = BzrGitMappingv1()
163
rev, roundtrip_revid, verifiers = mapping.import_commit(c,
164
mapping.revision_id_foreign_to_bzr)
165
self.assertEquals(None, roundtrip_revid)
166
self.assertEquals({}, verifiers)
167
self.assertEquals(u"Authér", rev.properties['author'])
168
self.assertTrue("git-explicit-encoding" not in rev.properties)
169
self.assertTrue("git-implicit-encoding" not in rev.properties)
172
class RoundtripRevisionsFromBazaar(tests.TestCase):
175
super(RoundtripRevisionsFromBazaar, self).setUp()
176
self.mapping = BzrGitMappingv1()
177
self._parent_map = {}
178
self._lookup_parent = self._parent_map.__getitem__
180
def assertRoundtripRevision(self, orig_rev):
181
commit = self.mapping.export_commit(orig_rev, "mysha",
182
self._lookup_parent, True, "testamentsha")
183
rev, roundtrip_revid, verifiers = self.mapping.import_commit(
184
commit, self.mapping.revision_id_foreign_to_bzr)
185
self.assertEquals(rev.revision_id,
186
self.mapping.revision_id_foreign_to_bzr(commit.id))
187
if self.mapping.roundtripping:
188
self.assertEquals({"testament3-sha1": "testamentsha"} , verifiers)
189
self.assertEquals(orig_rev.revision_id, roundtrip_revid)
190
self.assertEquals(orig_rev.properties, rev.properties)
191
self.assertEquals(orig_rev.committer, rev.committer)
192
self.assertEquals(orig_rev.timestamp, rev.timestamp)
193
self.assertEquals(orig_rev.timezone, rev.timezone)
194
self.assertEquals(orig_rev.message, rev.message)
195
self.assertEquals(list(orig_rev.parent_ids), list(rev.parent_ids))
197
self.assertEquals({}, verifiers)
199
def test_simple_commit(self):
200
r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
201
r.message = "MyCommitMessage"
203
r.committer = "Jelmer Vernooij <jelmer@apache.org>"
204
r.timestamp = 453543543
207
self.assertRoundtripRevision(r)
209
def test_revision_id(self):
210
r = Revision("myrevid")
211
r.message = "MyCommitMessage"
213
r.committer = "Jelmer Vernooij <jelmer@apache.org>"
214
r.timestamp = 453543543
217
self.assertRoundtripRevision(r)
219
def test_ghost_parent(self):
220
r = Revision("myrevid")
221
r.message = "MyCommitMessage"
222
r.parent_ids = ["iamaghost"]
223
r.committer = "Jelmer Vernooij <jelmer@apache.org>"
224
r.timestamp = 453543543
227
self.assertRoundtripRevision(r)
229
def test_custom_property(self):
230
r = Revision("myrevid")
231
r.message = "MyCommitMessage"
233
r.properties = {"fool": "bar"}
234
r.committer = "Jelmer Vernooij <jelmer@apache.org>"
235
r.timestamp = 453543543
237
self.assertRoundtripRevision(r)
240
97
class RoundtripRevisionsFromGit(tests.TestCase):
275
130
c.author = "Author <author>"
276
131
self.assertRoundtripCommit(c)
278
def test_commit_zero_utc_timezone(self):
280
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
281
c.message = "Some message"
282
c.committer = "Committer <Committer>"
284
c.commit_timezone = 0
285
c._commit_timezone_neg_utc = True
287
c.author_timezone = 60 * 2
288
c.author = "Author <author>"
289
self.assertRoundtripCommit(c)
291
def test_commit_encoding(self):
293
c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
294
c.message = "Some message"
295
c.committer = "Committer <Committer>"
296
c.encoding = 'iso8859-1'
298
c.commit_timezone = -60 * 3
300
c.author_timezone = 60 * 2
301
c.author = "Author <author>"
302
self.assertRoundtripCommit(c)
305
134
class DirectoryToTreeTests(tests.TestCase):
307
136
def test_empty(self):
308
137
ie = InventoryDirectory('foo', 'foo', 'foo')
309
t = directory_to_tree(ie, None, {}, None)
138
t = directory_to_tree(ie, None, {})
310
139
self.assertEquals(None, t)
312
141
def test_empty_dir(self):
313
142
ie = InventoryDirectory('foo', 'foo', 'foo')
314
143
child_ie = InventoryDirectory('bar', 'bar', 'bar')
315
144
ie.children['bar'] = child_ie
316
t = directory_to_tree(ie, lambda x: None, {}, None)
145
t = directory_to_tree(ie, lambda x: None, {})
317
146
self.assertEquals(None, t)
319
def test_empty_dir_dummy_files(self):
320
ie = InventoryDirectory('foo', 'foo', 'foo')
321
child_ie = InventoryDirectory('bar', 'bar', 'bar')
322
ie.children['bar'] = child_ie
323
t = directory_to_tree(ie, lambda x: None, {}, ".mydummy")
324
self.assertTrue(".mydummy" in t)
326
148
def test_empty_root(self):
327
149
ie = InventoryDirectory('foo', 'foo', None)
328
150
child_ie = InventoryDirectory('bar', 'bar', 'bar')
329
151
ie.children['bar'] = child_ie
330
t = directory_to_tree(ie, lambda x: None, {}, None)
152
t = directory_to_tree(ie, lambda x: None, {})
331
153
self.assertEquals(Tree(), t)
333
155
def test_with_file(self):