/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

Add docstring.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
2
# -*- encoding: utf-8 -*-
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
14
15
# along with this program; if not, write to the Free Software
15
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
 
 
18
from bzrlib.inventory import (
 
19
    InventoryDirectory,
 
20
    InventoryFile,
 
21
    )
 
22
 
17
23
from dulwich.objects import (
 
24
    Blob,
18
25
    Commit,
 
26
    Tree,
19
27
    )
20
28
 
21
29
from bzrlib.plugins.git import tests
22
30
from bzrlib.plugins.git.mapping import (
23
31
    BzrGitMappingv1,
 
32
    directory_to_tree,
24
33
    escape_file_id,
25
 
    revision_to_commit,
26
34
    unescape_file_id,
27
35
    )
28
36
 
84
92
        self.assertEquals("180", rev.properties['author-timezone'])
85
93
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
86
94
 
 
95
    def test_explicit_encoding(self):
 
96
        c = Commit()
 
97
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
98
        c.message = "Some message"
 
99
        c.committer = "Committer"
 
100
        c.commit_time = 4
 
101
        c.author_time = 5
 
102
        c.commit_timezone = 60 * 5
 
103
        c.author_timezone = 60 * 3
 
104
        c.author = u"Authér".encode("iso8859-1")
 
105
        c.encoding = "iso8859-1"
 
106
        c.serialize()
 
107
        rev = BzrGitMappingv1().import_commit(c)
 
108
        self.assertEquals(u"Authér", rev.properties['author'])
 
109
        self.assertEquals("iso8859-1", rev.properties["git-explicit-encoding"])
 
110
        self.assertTrue("git-implicit-encoding" not in rev.properties)
 
111
 
 
112
    def test_implicit_encoding_fallback(self):
 
113
        c = Commit()
 
114
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
115
        c.message = "Some message"
 
116
        c.committer = "Committer"
 
117
        c.commit_time = 4
 
118
        c.author_time = 5
 
119
        c.commit_timezone = 60 * 5
 
120
        c.author_timezone = 60 * 3
 
121
        c.author = u"Authér".encode("latin1")
 
122
        c.serialize()
 
123
        rev = BzrGitMappingv1().import_commit(c)
 
124
        self.assertEquals(u"Authér", rev.properties['author'])
 
125
        self.assertEquals("latin1", rev.properties["git-implicit-encoding"])
 
126
        self.assertTrue("git-explicit-encoding" not in rev.properties)
 
127
 
 
128
    def test_implicit_encoding_utf8(self):
 
129
        c = Commit()
 
130
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
131
        c.message = "Some message"
 
132
        c.committer = "Committer"
 
133
        c.commit_time = 4
 
134
        c.author_time = 5
 
135
        c.commit_timezone = 60 * 5
 
136
        c.author_timezone = 60 * 3
 
137
        c.author = u"Authér".encode("utf-8")
 
138
        c.serialize()
 
139
        rev = BzrGitMappingv1().import_commit(c)
 
140
        self.assertEquals(u"Authér", rev.properties['author'])
 
141
        self.assertTrue("git-explicit-encoding" not in rev.properties)
 
142
        self.assertTrue("git-implicit-encoding" not in rev.properties)
87
143
 
88
144
 
89
145
class RoundtripRevisionsFromGit(tests.TestCase):
101
157
    def assertRoundtripCommit(self, commit1):
102
158
        commit1.serialize()
103
159
        rev = self.mapping.import_commit(commit1)
104
 
        commit2 = revision_to_commit(rev, "12341212121212", None)
 
160
        commit2 = self.mapping.export_commit(rev, "12341212121212", None)
105
161
        self.assertEquals(commit1.committer, commit2.committer)
106
162
        self.assertEquals(commit1.commit_time, commit2.commit_time)
107
163
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
109
165
        self.assertEquals(commit1.author_time, commit2.author_time)
110
166
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
111
167
        self.assertEquals(commit1.message, commit2.message)
 
168
        self.assertEquals(commit1.encoding, commit2.encoding)
112
169
 
113
170
    def test_commit(self):
114
171
        c = Commit()
122
179
        c.author = "Author <author>"
123
180
        self.assertRoundtripCommit(c)
124
181
 
 
182
    def test_commit_encoding(self):
 
183
        c = Commit()
 
184
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
185
        c.message = "Some message"
 
186
        c.committer = "Committer <Committer>"
 
187
        c.encoding = 'iso8859-1'
 
188
        c.commit_time = 4
 
189
        c.commit_timezone = -60 * 3
 
190
        c.author_time = 5
 
191
        c.author_timezone = 60 * 2
 
192
        c.author = "Author <author>"
 
193
        self.assertRoundtripCommit(c)
 
194
 
 
195
 
 
196
class DirectoryToTreeTests(tests.TestCase):
 
197
 
 
198
    def test_empty(self):
 
199
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
200
        t = directory_to_tree(ie, None, {})
 
201
        self.assertEquals(None, t)
 
202
 
 
203
    def test_empty_dir(self):
 
204
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
205
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
206
        ie.children['bar'] = child_ie
 
207
        t = directory_to_tree(ie, lambda x: None, {})
 
208
        self.assertEquals(None, t)
 
209
 
 
210
    def test_empty_root(self):
 
211
        ie = InventoryDirectory('foo', 'foo', None)
 
212
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
213
        ie.children['bar'] = child_ie
 
214
        t = directory_to_tree(ie, lambda x: None, {})
 
215
        self.assertEquals(Tree(), t)
 
216
 
 
217
    def test_with_file(self):
 
218
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
219
        child_ie = InventoryFile('bar', 'bar', 'bar')
 
220
        ie.children['bar'] = child_ie
 
221
        b = Blob.from_string("bla")
 
222
        t1 = directory_to_tree(ie, lambda x: b.id, {})
 
223
        t2 = Tree()
 
224
        t2.add(0100644, "bar", b.id)
 
225
        self.assertEquals(t1, t2)