/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

Implement InterTree.iter_changes() as well.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
from bzrlib.inventory import (
 
18
    InventoryDirectory,
 
19
    InventoryFile,
 
20
    )
 
21
 
 
22
from dulwich.objects import (
 
23
    Blob,
 
24
    Commit,
 
25
    Tree,
 
26
    )
 
27
 
 
28
from bzrlib.plugins.git import tests
 
29
from bzrlib.plugins.git.mapping import (
 
30
    BzrGitMappingv1,
 
31
    directory_to_tree,
 
32
    escape_file_id,
 
33
    revision_to_commit,
 
34
    unescape_file_id,
 
35
    )
 
36
 
 
37
 
 
38
class TestRevidConversionV1(tests.TestCase):
 
39
 
 
40
    def test_simple_git_to_bzr_revision_id(self):
 
41
        self.assertEqual("git-v1:"
 
42
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
 
43
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
 
44
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
 
45
 
 
46
    def test_simple_bzr_to_git_revision_id(self):
 
47
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
 
48
                         BzrGitMappingv1()),
 
49
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
 
50
                            "git-v1:"
 
51
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
 
52
 
 
53
 
 
54
class FileidTests(tests.TestCase):
 
55
 
 
56
    def test_escape_space(self):
 
57
        self.assertEquals("bla_s", escape_file_id("bla "))
 
58
 
 
59
    def test_escape_underscore(self):
 
60
        self.assertEquals("bla__", escape_file_id("bla_"))
 
61
 
 
62
    def test_escape_underscore_space(self):
 
63
        self.assertEquals("bla___s", escape_file_id("bla_ "))
 
64
 
 
65
    def test_unescape_underscore(self):
 
66
        self.assertEquals("bla ", unescape_file_id("bla_s"))
 
67
 
 
68
    def test_unescape_underscore_space(self):
 
69
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
 
70
 
 
71
 
 
72
class TestImportCommit(tests.TestCase):
 
73
 
 
74
    def test_commit(self):
 
75
        c = Commit()
 
76
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
77
        c.message = "Some message"
 
78
        c.committer = "Committer"
 
79
        c.commit_time = 4
 
80
        c.author_time = 5
 
81
        c.commit_timezone = 60 * 5
 
82
        c.author_timezone = 60 * 3
 
83
        c.author = "Author"
 
84
        c.serialize()
 
85
        rev = BzrGitMappingv1().import_commit(c)
 
86
        self.assertEquals("Some message", rev.message)
 
87
        self.assertEquals("Committer", rev.committer)
 
88
        self.assertEquals("Author", rev.properties['author'])
 
89
        self.assertEquals(300, rev.timezone)
 
90
        self.assertEquals((), rev.parent_ids)
 
91
        self.assertEquals("5", rev.properties['author-timestamp'])
 
92
        self.assertEquals("180", rev.properties['author-timezone'])
 
93
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
 
94
 
 
95
 
 
96
 
 
97
class RoundtripRevisionsFromGit(tests.TestCase):
 
98
 
 
99
    def setUp(self):
 
100
        super(RoundtripRevisionsFromGit, self).setUp()
 
101
        self.mapping = BzrGitMappingv1()
 
102
 
 
103
    def assertRoundtripTree(self, tree):
 
104
        raise NotImplementedError(self.assertRoundtripTree)
 
105
 
 
106
    def assertRoundtripBlob(self, blob):
 
107
        raise NotImplementedError(self.assertRoundtripBlob)
 
108
 
 
109
    def assertRoundtripCommit(self, commit1):
 
110
        commit1.serialize()
 
111
        rev = self.mapping.import_commit(commit1)
 
112
        commit2 = revision_to_commit(rev, "12341212121212", None)
 
113
        self.assertEquals(commit1.committer, commit2.committer)
 
114
        self.assertEquals(commit1.commit_time, commit2.commit_time)
 
115
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
 
116
        self.assertEquals(commit1.author, commit2.author)
 
117
        self.assertEquals(commit1.author_time, commit2.author_time)
 
118
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
 
119
        self.assertEquals(commit1.message, commit2.message)
 
120
 
 
121
    def test_commit(self):
 
122
        c = Commit()
 
123
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
124
        c.message = "Some message"
 
125
        c.committer = "Committer <Committer>"
 
126
        c.commit_time = 4
 
127
        c.commit_timezone = -60 * 3
 
128
        c.author_time = 5
 
129
        c.author_timezone = 60 * 2
 
130
        c.author = "Author <author>"
 
131
        self.assertRoundtripCommit(c)
 
132
 
 
133
 
 
134
class DirectoryToTreeTests(tests.TestCase):
 
135
 
 
136
    def test_empty(self):
 
137
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
138
        t = directory_to_tree(ie, None, {})
 
139
        self.assertEquals(None, t)
 
140
 
 
141
    def test_empty_dir(self):
 
142
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
143
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
144
        ie.children['bar'] = child_ie
 
145
        t = directory_to_tree(ie, lambda x: None, {})
 
146
        self.assertEquals(None, t)
 
147
 
 
148
    def test_empty_root(self):
 
149
        ie = InventoryDirectory('foo', 'foo', None)
 
150
        child_ie = InventoryDirectory('bar', 'bar', 'bar')
 
151
        ie.children['bar'] = child_ie
 
152
        t = directory_to_tree(ie, lambda x: None, {})
 
153
        self.assertEquals(Tree(), t)
 
154
 
 
155
    def test_with_file(self):
 
156
        ie = InventoryDirectory('foo', 'foo', 'foo')
 
157
        child_ie = InventoryFile('bar', 'bar', 'bar')
 
158
        ie.children['bar'] = child_ie
 
159
        b = Blob.from_string("bla")
 
160
        t1 = directory_to_tree(ie, lambda x: b.id, {})
 
161
        t2 = Tree()
 
162
        t2.add(0100644, "bar", b.id)
 
163
        self.assertEquals(t1, t2)