/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_mapping.py

Use blob.chunked.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
    InventoryDirectory,
20
20
    InventoryFile,
21
21
    )
22
 
from bzrlib.revision import (
23
 
    Revision,
24
 
    )
25
22
 
26
23
from dulwich.objects import (
27
24
    Blob,
53
50
                            "git-v1:"
54
51
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
55
52
 
56
 
    def test_is_control_file(self):
57
 
        mapping = BzrGitMappingv1()
58
 
        if mapping.roundtripping:
59
 
            self.assertTrue(mapping.is_control_file(".bzrdummy"))
60
 
            self.assertTrue(mapping.is_control_file(".bzrfileids"))
61
 
        self.assertFalse(mapping.is_control_file(".bzrfoo"))
62
 
 
63
 
    def test_generate_file_id(self):
64
 
        mapping = BzrGitMappingv1()
65
 
        self.assertIsInstance(mapping.generate_file_id("la"), str)
66
 
        self.assertIsInstance(mapping.generate_file_id(u"é"), str)
67
 
 
68
53
 
69
54
class FileidTests(tests.TestCase):
70
55
 
96
81
        c.commit_timezone = 60 * 5
97
82
        c.author_timezone = 60 * 3
98
83
        c.author = "Author"
99
 
        mapping = BzrGitMappingv1()
100
 
        rev, roundtrip_revid, verifiers = mapping.import_commit(c,
101
 
            mapping.revision_id_foreign_to_bzr)
102
 
        self.assertEquals(None, roundtrip_revid)
103
 
        self.assertEquals({}, verifiers)
 
84
        rev = BzrGitMappingv1().import_commit(c)
104
85
        self.assertEquals("Some message", rev.message)
105
86
        self.assertEquals("Committer", rev.committer)
106
87
        self.assertEquals("Author", rev.properties['author'])
121
102
        c.author_timezone = 60 * 3
122
103
        c.author = u"Authér".encode("iso8859-1")
123
104
        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)
 
105
        rev = BzrGitMappingv1().import_commit(c)
129
106
        self.assertEquals(u"Authér", rev.properties['author'])
130
107
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
131
108
        self.assertTrue("git-implicit-encoding" not in rev.properties)
140
117
        c.commit_timezone = 60 * 5
141
118
        c.author_timezone = 60 * 3
142
119
        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)
 
120
        rev = BzrGitMappingv1().import_commit(c)
148
121
        self.assertEquals(u"Authér", rev.properties['author'])
149
122
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
150
123
        self.assertTrue("git-explicit-encoding" not in rev.properties)
159
132
        c.commit_timezone = 60 * 5
160
133
        c.author_timezone = 60 * 3
161
134
        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)
 
135
        rev = BzrGitMappingv1().import_commit(c)
167
136
        self.assertEquals(u"Authér", rev.properties['author'])
168
137
        self.assertTrue("git-explicit-encoding" not in rev.properties)
169
138
        self.assertTrue("git-implicit-encoding" not in rev.properties)
170
139
 
171
140
 
172
 
class RoundtripRevisionsFromBazaar(tests.TestCase):
173
 
 
174
 
    def setUp(self):
175
 
        super(RoundtripRevisionsFromBazaar, self).setUp()
176
 
        self.mapping = BzrGitMappingv1()
177
 
        self._parent_map = {}
178
 
        self._lookup_parent = self._parent_map.__getitem__
179
 
 
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))
196
 
        else:
197
 
            self.assertEquals({}, verifiers)
198
 
 
199
 
    def test_simple_commit(self):
200
 
        r = Revision(self.mapping.revision_id_foreign_to_bzr("edf99e6c56495c620f20d5dacff9859ff7119261"))
201
 
        r.message = "MyCommitMessage"
202
 
        r.parent_ids = []
203
 
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
204
 
        r.timestamp = 453543543
205
 
        r.timezone = 0
206
 
        r.properties = {}
207
 
        self.assertRoundtripRevision(r)
208
 
 
209
 
    def test_revision_id(self):
210
 
        r = Revision("myrevid")
211
 
        r.message = "MyCommitMessage"
212
 
        r.parent_ids = []
213
 
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
214
 
        r.timestamp = 453543543
215
 
        r.timezone = 0
216
 
        r.properties = {}
217
 
        self.assertRoundtripRevision(r)
218
 
 
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
225
 
        r.timezone = 0
226
 
        r.properties = {}
227
 
        self.assertRoundtripRevision(r)
228
 
 
229
 
    def test_custom_property(self):
230
 
        r = Revision("myrevid")
231
 
        r.message = "MyCommitMessage"
232
 
        r.parent_ids = []
233
 
        r.properties = {"fool": "bar"}
234
 
        r.committer = "Jelmer Vernooij <jelmer@apache.org>"
235
 
        r.timestamp = 453543543
236
 
        r.timezone = 0
237
 
        self.assertRoundtripRevision(r)
238
 
 
239
 
 
240
141
class RoundtripRevisionsFromGit(tests.TestCase):
241
142
 
242
143
    def setUp(self):
250
151
        raise NotImplementedError(self.assertRoundtripBlob)
251
152
 
252
153
    def assertRoundtripCommit(self, commit1):
253
 
        rev, roundtrip_revid, verifiers = self.mapping.import_commit(
254
 
            commit1, self.mapping.revision_id_foreign_to_bzr)
255
 
        commit2 = self.mapping.export_commit(rev, "12341212121212", None,
256
 
            True, None)
 
154
        rev = self.mapping.import_commit(commit1)
 
155
        commit2 = self.mapping.export_commit(rev, "12341212121212", None)
257
156
        self.assertEquals(commit1.committer, commit2.committer)
258
157
        self.assertEquals(commit1.commit_time, commit2.commit_time)
259
158
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
275
174
        c.author = "Author <author>"
276
175
        self.assertRoundtripCommit(c)
277
176
 
278
 
    def test_commit_zero_utc_timezone(self):
279
 
        c = Commit()
280
 
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
281
 
        c.message = "Some message"
282
 
        c.committer = "Committer <Committer>"
283
 
        c.commit_time = 4
284
 
        c.commit_timezone = 0
285
 
        c._commit_timezone_neg_utc = True
286
 
        c.author_time = 5
287
 
        c.author_timezone = 60 * 2
288
 
        c.author = "Author <author>"
289
 
        self.assertRoundtripCommit(c)
290
 
 
291
177
    def test_commit_encoding(self):
292
178
        c = Commit()
293
179
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
306
192
 
307
193
    def test_empty(self):
308
194
        ie = InventoryDirectory('foo', 'foo', 'foo')
309
 
        t = directory_to_tree(ie, None, {}, None)
 
195
        t = directory_to_tree(ie, None, {})
310
196
        self.assertEquals(None, t)
311
197
 
312
198
    def test_empty_dir(self):
313
199
        ie = InventoryDirectory('foo', 'foo', 'foo')
314
200
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
315
201
        ie.children['bar'] = child_ie
316
 
        t = directory_to_tree(ie, lambda x: None, {}, None)
 
202
        t = directory_to_tree(ie, lambda x: None, {})
317
203
        self.assertEquals(None, t)
318
204
 
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)
325
 
 
326
205
    def test_empty_root(self):
327
206
        ie = InventoryDirectory('foo', 'foo', None)
328
207
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
329
208
        ie.children['bar'] = child_ie
330
 
        t = directory_to_tree(ie, lambda x: None, {}, None)
 
209
        t = directory_to_tree(ie, lambda x: None, {})
331
210
        self.assertEquals(Tree(), t)
332
211
 
333
212
    def test_with_file(self):
335
214
        child_ie = InventoryFile('bar', 'bar', 'bar')
336
215
        ie.children['bar'] = child_ie
337
216
        b = Blob.from_string("bla")
338
 
        t1 = directory_to_tree(ie, lambda x: b.id, {}, None)
 
217
        t1 = directory_to_tree(ie, lambda x: b.id, {})
339
218
        t2 = Tree()
340
219
        t2.add(0100644, "bar", b.id)
341
220
        self.assertEquals(t1, t2)