/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
1
# Copyright (C) 2009 Canonical Ltd
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
"""Test how Commands are displayed"""
18
19
from bzrlib import tests
20
21
from bzrlib.plugins.fastimport import (
22
    commands,
23
    )
24
25
26
class TestBlobDisplay(tests.TestCase):
27
28
    def test_blob(self):
29
        c = commands.BlobCommand("1", "hello world")
30
        self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c))
31
32
    def test_blob_no_mark(self):
33
        c = commands.BlobCommand(None, "hello world")
34
        self.assertEqual("blob\ndata 11\nhello world", repr(c))
35
36
37
class TestCheckpointDisplay(tests.TestCase):
38
39
    def test_checkpoint(self):
40
        c = commands.CheckpointCommand()
41
        self.assertEqual("checkpoint", repr(c))
42
43
44
class TestCommitDisplay(tests.TestCase):
45
46
    def test_commit(self):
47
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
48
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
49
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
0.77.4 by Ian Clatworthy
tweak from and merge formatting
50
            "release v1.0", ":aaa", None, None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
51
        self.assertEqualDiff(
52
            "commit refs/heads/master\n"
53
            "mark :bbb\n"
54
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
55
            "data 12\n"
56
            "release v1.0\n"
57
            "from :aaa",
58
            repr(c))
59
0.64.132 by Ian Clatworthy
fix fast-export's encoding of user names
60
    def test_commit_unicode_committer(self):
61
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
62
        name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'
63
        name_utf8 = name.encode('utf8')
64
        committer = (name, 'test@example.com', 1234567890, -6 * 3600)
65
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
66
            "release v1.0", ":aaa", None, None)
67
        self.assertEqualDiff(
68
            "commit refs/heads/master\n"
69
            "mark :bbb\n"
70
            "committer %s <test@example.com> 1234567890 -0600\n"
71
            "data 12\n"
72
            "release v1.0\n"
73
            "from :aaa" % (name_utf8,),
74
            repr(c))
75
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
76
    def test_commit_no_mark(self):
77
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
78
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
79
        c = commands.CommitCommand("refs/heads/master", None, None, committer,
0.77.4 by Ian Clatworthy
tweak from and merge formatting
80
            "release v1.0", ":aaa", None, None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
81
        self.assertEqualDiff(
82
            "commit refs/heads/master\n"
83
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
84
            "data 12\n"
85
            "release v1.0\n"
86
            "from :aaa",
87
            repr(c))
88
89
    def test_commit_no_from(self):
90
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
91
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
92
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
93
            "release v1.0", None, None, None)
94
        self.assertEqualDiff(
95
            "commit refs/heads/master\n"
96
            "mark :bbb\n"
97
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
98
            "data 12\n"
99
            "release v1.0",
100
            repr(c))
101
102
    def test_commit_with_author(self):
103
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
104
        author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
105
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
106
        c = commands.CommitCommand("refs/heads/master", "bbb", author,
0.77.4 by Ian Clatworthy
tweak from and merge formatting
107
            committer, "release v1.0", ":aaa", None, None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
108
        self.assertEqualDiff(
109
            "commit refs/heads/master\n"
110
            "mark :bbb\n"
111
            "author Sue Wong <sue@example.com> 1234565432 -0600\n"
112
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
113
            "data 12\n"
114
            "release v1.0\n"
115
            "from :aaa",
116
            repr(c))
117
118
    def test_commit_with_merges(self):
119
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
120
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
121
        c = commands.CommitCommand("refs/heads/master", "ddd", None, committer,
0.77.4 by Ian Clatworthy
tweak from and merge formatting
122
                "release v1.0", ":aaa", [':bbb', ':ccc'], None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
123
        self.assertEqualDiff(
124
            "commit refs/heads/master\n"
125
            "mark :ddd\n"
126
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
127
            "data 12\n"
128
            "release v1.0\n"
129
            "from :aaa\n"
130
            "merge :bbb\n"
131
            "merge :ccc",
132
            repr(c))
133
134
    def test_commit_with_filecommands(self):
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
135
        file_cmds = iter([
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
136
            commands.FileDeleteCommand('readme.txt'),
137
            commands.FileModifyCommand('NEWS', 'file', False, None,
138
                'blah blah blah'),
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
139
            ])
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
140
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
141
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
142
        c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
0.77.4 by Ian Clatworthy
tweak from and merge formatting
143
            "release v1.0", ":aaa", None, file_cmds)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
144
        self.assertEqualDiff(
145
            "commit refs/heads/master\n"
146
            "mark :bbb\n"
147
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
148
            "data 12\n"
149
            "release v1.0\n"
150
            "from :aaa\n"
151
            "D readme.txt\n"
152
            "M 644 inline NEWS\n"
153
            "data 14\n"
154
            "blah blah blah",
155
            repr(c))
156
157
158
class TestProgressDisplay(tests.TestCase):
159
160
    def test_progress(self):
161
        c = commands.ProgressCommand("doing foo")
162
        self.assertEqual("progress doing foo", repr(c))
163
164
165
class TestResetDisplay(tests.TestCase):
166
167
    def test_reset(self):
0.77.6 by Ian Clatworthy
no filtering tests
168
        c = commands.ResetCommand("refs/tags/v1.0", ":xxx")
0.79.5 by Ian Clatworthy
incorporate git-fast-import tweaks from bzr-fast-export script
169
        self.assertEqual("reset refs/tags/v1.0\nfrom :xxx\n", repr(c))
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
170
171
    def test_reset_no_from(self):
172
        c = commands.ResetCommand("refs/remotes/origin/master", None)
173
        self.assertEqual("reset refs/remotes/origin/master", repr(c))
174
175
176
class TestTagDisplay(tests.TestCase):
177
178
    def test_tag(self):
179
        # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
180
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
0.77.6 by Ian Clatworthy
no filtering tests
181
        c = commands.TagCommand("refs/tags/v1.0", ":xxx", tagger, "create v1.0")
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
182
        self.assertEqual(
183
            "tag refs/tags/v1.0\n"
184
            "from :xxx\n"
185
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
186
            "data 11\n"
187
            "create v1.0",
188
            repr(c))
189
190
    def test_tag_no_from(self):
191
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
192
        c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
193
        self.assertEqualDiff(
194
            "tag refs/tags/v1.0\n"
195
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
196
            "data 11\n"
197
            "create v1.0",
198
            repr(c))
199
200
201
class TestFileModifyDisplay(tests.TestCase):
202
203
    def test_filemodify_file(self):
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
204
        c = commands.FileModifyCommand("foo/bar", "file", False, ":23", None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
205
        self.assertEqual("M 644 :23 foo/bar", repr(c))
206
207
    def test_filemodify_file_executable(self):
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
208
        c = commands.FileModifyCommand("foo/bar", "file", True, ":23", None)
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
209
        self.assertEqual("M 755 :23 foo/bar", repr(c))
210
211
    def test_filemodify_file_internal(self):
212
        c = commands.FileModifyCommand("foo/bar", "file", False, None,
213
            "hello world")
214
        self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
215
216
    def test_filemodify_symlink(self):
217
        c = commands.FileModifyCommand("foo/bar", "symlink", False, None, "baz")
218
        self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
219
220
221
class TestFileDeleteDisplay(tests.TestCase):
222
223
    def test_filedelete(self):
224
        c = commands.FileDeleteCommand("foo/bar")
225
        self.assertEqual("D foo/bar", repr(c))
226
227
228
class TestFileCopyDisplay(tests.TestCase):
229
230
    def test_filecopy(self):
231
        c = commands.FileCopyCommand("foo/bar", "foo/baz")
232
        self.assertEqual("C foo/bar foo/baz", repr(c))
233
234
    def test_filecopy_quoted(self):
235
        # Check the first path is quoted if it contains spaces
236
        c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
237
        self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
238
239
240
class TestFileRenameDisplay(tests.TestCase):
241
242
    def test_filerename(self):
243
        c = commands.FileRenameCommand("foo/bar", "foo/baz")
244
        self.assertEqual("R foo/bar foo/baz", repr(c))
245
246
    def test_filerename_quoted(self):
247
        # Check the first path is quoted if it contains spaces
248
        c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
249
        self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
250
251
252
class TestFileDeleteAllDisplay(tests.TestCase):
253
254
    def test_filedeleteall(self):
255
        c = commands.FileDeleteAllCommand()
256
        self.assertEqual("deleteall", repr(c))
0.64.147 by Ian Clatworthy
error on zero length paths in the input stream
257
258
259
class TestPathChecking(tests.TestCase):
260
261
    def test_filemodify_path_checking(self):
262
        self.assertRaises(ValueError, commands.FileModifyCommand, "",
263
            "file", False, None, "text")
264
        self.assertRaises(ValueError, commands.FileModifyCommand, None,
265
            "file", False, None, "text")
266
267
    def test_filedelete_path_checking(self):
268
        self.assertRaises(ValueError, commands.FileDeleteCommand, "")
269
        self.assertRaises(ValueError, commands.FileDeleteCommand, None)
270
271
    def test_filerename_path_checking(self):
272
        self.assertRaises(ValueError, commands.FileRenameCommand, "", "foo")
273
        self.assertRaises(ValueError, commands.FileRenameCommand, None, "foo")
274
        self.assertRaises(ValueError, commands.FileRenameCommand, "foo", "")
275
        self.assertRaises(ValueError, commands.FileRenameCommand, "foo", None)
276
277
    def test_filecopy_path_checking(self):
278
        self.assertRaises(ValueError, commands.FileCopyCommand, "", "foo")
279
        self.assertRaises(ValueError, commands.FileCopyCommand, None, "foo")
280
        self.assertRaises(ValueError, commands.FileCopyCommand, "foo", "")
281
        self.assertRaises(ValueError, commands.FileCopyCommand, "foo", None)