/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

Update docs.

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