/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

Fix support for older versions of Dulwich.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
from bzrlib.inventory import (
 
18
    InventoryDirectory,
 
19
    InventoryFile,
 
20
    )
 
21
 
17
22
from dulwich.objects import (
 
23
    Blob,
18
24
    Commit,
 
25
    Tree,
19
26
    )
20
27
 
21
28
from bzrlib.plugins.git import tests
22
29
from bzrlib.plugins.git.mapping import (
23
30
    BzrGitMappingv1,
 
31
    directory_to_tree,
24
32
    escape_file_id,
25
 
    revision_to_commit,
26
33
    unescape_file_id,
27
34
    )
28
35
 
101
108
    def assertRoundtripCommit(self, commit1):
102
109
        commit1.serialize()
103
110
        rev = self.mapping.import_commit(commit1)
104
 
        commit2 = revision_to_commit(rev, "12341212121212", None)
 
111
        commit2 = self.mapping.export_commit(rev, "12341212121212", None)
105
112
        self.assertEquals(commit1.committer, commit2.committer)
106
113
        self.assertEquals(commit1.commit_time, commit2.commit_time)
107
114
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
122
129
        c.author = "Author <author>"
123
130
        self.assertRoundtripCommit(c)
124
131
 
 
132
 
 
133
class DirectoryToTreeTests(tests.TestCase):
 
134
 
 
135
    def test_empty(self):
 
136
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
137
        t = directory_to_tree(ie, None, {})
 
138
        self.assertEquals(None, t)
 
139
 
 
140
    def test_empty_dir(self):
 
141
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
142
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
143
        ie.children['bar'] = child_ie
 
144
        t = directory_to_tree(ie, lambda x: None, {})
 
145
        self.assertEquals(None, t)
 
146
 
 
147
    def test_empty_root(self):
 
148
        ie = InventoryDirectory('foo', 'foo', None)
 
149
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
150
        ie.children['bar'] = child_ie
 
151
        t = directory_to_tree(ie, lambda x: None, {})
 
152
        self.assertEquals(Tree(), t)
 
153
 
 
154
    def test_with_file(self):
 
155
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
156
        child_ie = InventoryFile('bar', 'bar', 'bar')
 
157
        ie.children['bar'] = child_ie
 
158
        b = Blob.from_string("bla")
 
159
        t1 = directory_to_tree(ie, lambda x: b.id, {})
 
160
        t2 = Tree()
 
161
        t2.add(0100644, "bar", b.id)
 
162
        self.assertEquals(t1, t2)