/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

Default to using global user id rather than making one up.

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 dulwich.objects import (
 
18
    Commit,
 
19
    )
 
20
 
 
21
from bzrlib.plugins.git import tests
 
22
from bzrlib.plugins.git.mapping import (
 
23
    BzrGitMappingv1,
 
24
    escape_file_id,
 
25
    revision_to_commit,
 
26
    unescape_file_id,
 
27
    )
 
28
 
 
29
 
 
30
class TestRevidConversionV1(tests.TestCase):
 
31
 
 
32
    def test_simple_git_to_bzr_revision_id(self):
 
33
        self.assertEqual("git-v1:"
 
34
                         "c6a4d8f1fa4ac650748e647c4b1b368f589a7356",
 
35
                         BzrGitMappingv1().revision_id_foreign_to_bzr(
 
36
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
 
37
 
 
38
    def test_simple_bzr_to_git_revision_id(self):
 
39
        self.assertEqual(("c6a4d8f1fa4ac650748e647c4b1b368f589a7356", 
 
40
                         BzrGitMappingv1()),
 
41
                         BzrGitMappingv1().revision_id_bzr_to_foreign(
 
42
                            "git-v1:"
 
43
                            "c6a4d8f1fa4ac650748e647c4b1b368f589a7356"))
 
44
 
 
45
 
 
46
class FileidTests(tests.TestCase):
 
47
 
 
48
    def test_escape_space(self):
 
49
        self.assertEquals("bla_s", escape_file_id("bla "))
 
50
 
 
51
    def test_escape_underscore(self):
 
52
        self.assertEquals("bla__", escape_file_id("bla_"))
 
53
 
 
54
    def test_escape_underscore_space(self):
 
55
        self.assertEquals("bla___s", escape_file_id("bla_ "))
 
56
 
 
57
    def test_unescape_underscore(self):
 
58
        self.assertEquals("bla ", unescape_file_id("bla_s"))
 
59
 
 
60
    def test_unescape_underscore_space(self):
 
61
        self.assertEquals("bla _", unescape_file_id("bla_s__"))
 
62
 
 
63
 
 
64
class TestImportCommit(tests.TestCase):
 
65
 
 
66
    def test_commit(self):
 
67
        c = Commit()
 
68
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
69
        c.message = "Some message"
 
70
        c.committer = "Committer"
 
71
        c.commit_time = 4
 
72
        c.author_time = 5
 
73
        c.commit_timezone = 60 * 5
 
74
        c.author_timezone = 60 * 3
 
75
        c.author = "Author"
 
76
        c.serialize()
 
77
        rev = BzrGitMappingv1().import_commit(c)
 
78
        self.assertEquals("Some message", rev.message)
 
79
        self.assertEquals("Committer", rev.committer)
 
80
        self.assertEquals("Author", rev.properties['author'])
 
81
        self.assertEquals(300, rev.timezone)
 
82
        self.assertEquals((), rev.parent_ids)
 
83
        self.assertEquals("5", rev.properties['author-timestamp'])
 
84
        self.assertEquals("180", rev.properties['author-timezone'])
 
85
        self.assertEquals("git-v1:" + c.id, rev.revision_id)
 
86
 
 
87
 
 
88
 
 
89
class RoundtripRevisionsFromGit(tests.TestCase):
 
90
 
 
91
    def setUp(self):
 
92
        super(RoundtripRevisionsFromGit, self).setUp()
 
93
        self.mapping = BzrGitMappingv1()
 
94
 
 
95
    def assertRoundtripTree(self, tree):
 
96
        raise NotImplementedError(self.assertRoundtripTree)
 
97
 
 
98
    def assertRoundtripBlob(self, blob):
 
99
        raise NotImplementedError(self.assertRoundtripBlob)
 
100
 
 
101
    def assertRoundtripCommit(self, commit1):
 
102
        commit1.serialize()
 
103
        rev = self.mapping.import_commit(commit1)
 
104
        commit2 = revision_to_commit(rev, "12341212121212", None)
 
105
        self.assertEquals(commit1.committer, commit2.committer)
 
106
        self.assertEquals(commit1.commit_time, commit2.commit_time)
 
107
        self.assertEquals(commit1.commit_timezone, commit2.commit_timezone)
 
108
        self.assertEquals(commit1.author, commit2.author)
 
109
        self.assertEquals(commit1.author_time, commit2.author_time)
 
110
        self.assertEquals(commit1.author_timezone, commit2.author_timezone)
 
111
        self.assertEquals(commit1.message, commit2.message)
 
112
 
 
113
    def test_commit(self):
 
114
        c = Commit()
 
115
        c.tree = "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
 
116
        c.message = "Some message"
 
117
        c.committer = "Committer <Committer>"
 
118
        c.commit_time = 4
 
119
        c.commit_timezone = -60 * 3
 
120
        c.author_time = 5
 
121
        c.author_timezone = 60 * 2
 
122
        c.author = "Author <author>"
 
123
        self.assertRoundtripCommit(c)
 
124