/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
0.102.2 by Ian Clatworthy
Definition and formatting of multiple authors and revision properties
157
    def test_commit_with_more_authors(self):
158
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
159
        author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
160
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
161
        more_authors = [
162
            ('Al Smith', 'al@example.com', 1234565432, -6 * 3600),
163
            ('Bill Jones', 'bill@example.com', 1234565432, -6 * 3600),
164
            ]
165
        c = commands.CommitCommand("refs/heads/master", "bbb", author,
166
            committer, "release v1.0", ":aaa", None, None, more_authors)
167
        self.assertEqualDiff(
168
            "commit refs/heads/master\n"
169
            "mark :bbb\n"
170
            "author Sue Wong <sue@example.com> 1234565432 -0600\n"
171
            "author Al Smith <al@example.com> 1234565432 -0600\n"
172
            "author Bill Jones <bill@example.com> 1234565432 -0600\n"
173
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
174
            "data 12\n"
175
            "release v1.0\n"
176
            "from :aaa",
177
            repr(c))
178
179
    def test_commit_with_properties(self):
180
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
181
        committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
182
        properties = {
183
            u'greeting':  u'hello',
184
            u'planet':    u'world',
185
            }
186
        c = commands.CommitCommand("refs/heads/master", "bbb", None,
187
            committer, "release v1.0", ":aaa", None, None, None, properties)
188
        self.assertEqualDiff(
189
            "commit refs/heads/master\n"
190
            "mark :bbb\n"
191
            "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
192
            "data 12\n"
193
            "release v1.0\n"
194
            "from :aaa\n"
195
            "properties 2\n"
196
            "name 8 greeting\n"
197
            "value 5 hello\n"
198
            "name 6 planet\n"
199
            "value 5 world",
200
            repr(c))
201
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
202
0.102.1 by Ian Clatworthy
Definition and output of feature commands
203
class TestFeatureDisplay(tests.TestCase):
204
205
    def test_feature(self):
206
        c = commands.FeatureCommand("dwim")
207
        self.assertEqual("feature dwim", repr(c))
208
209
    def test_feature_with_value(self):
210
        c = commands.FeatureCommand("dwim", "please")
211
        self.assertEqual("feature dwim=please", repr(c))
212
213
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
214
class TestProgressDisplay(tests.TestCase):
215
216
    def test_progress(self):
217
        c = commands.ProgressCommand("doing foo")
218
        self.assertEqual("progress doing foo", repr(c))
219
220
221
class TestResetDisplay(tests.TestCase):
222
223
    def test_reset(self):
0.77.6 by Ian Clatworthy
no filtering tests
224
        c = commands.ResetCommand("refs/tags/v1.0", ":xxx")
0.79.5 by Ian Clatworthy
incorporate git-fast-import tweaks from bzr-fast-export script
225
        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
226
227
    def test_reset_no_from(self):
228
        c = commands.ResetCommand("refs/remotes/origin/master", None)
229
        self.assertEqual("reset refs/remotes/origin/master", repr(c))
230
231
232
class TestTagDisplay(tests.TestCase):
233
234
    def test_tag(self):
235
        # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
236
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
0.77.6 by Ian Clatworthy
no filtering tests
237
        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
238
        self.assertEqual(
239
            "tag refs/tags/v1.0\n"
240
            "from :xxx\n"
241
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
242
            "data 11\n"
243
            "create v1.0",
244
            repr(c))
245
246
    def test_tag_no_from(self):
247
        tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
248
        c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
249
        self.assertEqualDiff(
250
            "tag refs/tags/v1.0\n"
251
            "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
252
            "data 11\n"
253
            "create v1.0",
254
            repr(c))
255
256
257
class TestFileModifyDisplay(tests.TestCase):
258
259
    def test_filemodify_file(self):
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
260
        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
261
        self.assertEqual("M 644 :23 foo/bar", repr(c))
262
263
    def test_filemodify_file_executable(self):
0.77.3 by Ian Clatworthy
get fast-import-filter formatting commands in the output correctly
264
        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
265
        self.assertEqual("M 755 :23 foo/bar", repr(c))
266
267
    def test_filemodify_file_internal(self):
268
        c = commands.FileModifyCommand("foo/bar", "file", False, None,
269
            "hello world")
270
        self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
271
272
    def test_filemodify_symlink(self):
273
        c = commands.FileModifyCommand("foo/bar", "symlink", False, None, "baz")
274
        self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
275
0.64.229 by Ian Clatworthy
Handle git submodules in the stream by warning about + ignoring them
276
    def test_filemodify_treeref(self):
277
        c = commands.FileModifyCommand("tree-info", "tree-reference", False,
278
            "revision-id-info", None)
279
        self.assertEqual("M 160000 revision-id-info tree-info", repr(c))
280
0.77.2 by Ian Clatworthy
code & tests for formatting Commands as file-import stream strings
281
282
class TestFileDeleteDisplay(tests.TestCase):
283
284
    def test_filedelete(self):
285
        c = commands.FileDeleteCommand("foo/bar")
286
        self.assertEqual("D foo/bar", repr(c))
287
288
289
class TestFileCopyDisplay(tests.TestCase):
290
291
    def test_filecopy(self):
292
        c = commands.FileCopyCommand("foo/bar", "foo/baz")
293
        self.assertEqual("C foo/bar foo/baz", repr(c))
294
295
    def test_filecopy_quoted(self):
296
        # Check the first path is quoted if it contains spaces
297
        c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
298
        self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
299
300
301
class TestFileRenameDisplay(tests.TestCase):
302
303
    def test_filerename(self):
304
        c = commands.FileRenameCommand("foo/bar", "foo/baz")
305
        self.assertEqual("R foo/bar foo/baz", repr(c))
306
307
    def test_filerename_quoted(self):
308
        # Check the first path is quoted if it contains spaces
309
        c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
310
        self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
311
312
313
class TestFileDeleteAllDisplay(tests.TestCase):
314
315
    def test_filedeleteall(self):
316
        c = commands.FileDeleteAllCommand()
317
        self.assertEqual("deleteall", repr(c))
0.64.147 by Ian Clatworthy
error on zero length paths in the input stream
318
319
320
class TestPathChecking(tests.TestCase):
321
322
    def test_filemodify_path_checking(self):
323
        self.assertRaises(ValueError, commands.FileModifyCommand, "",
324
            "file", False, None, "text")
325
        self.assertRaises(ValueError, commands.FileModifyCommand, None,
326
            "file", False, None, "text")
327
328
    def test_filedelete_path_checking(self):
329
        self.assertRaises(ValueError, commands.FileDeleteCommand, "")
330
        self.assertRaises(ValueError, commands.FileDeleteCommand, None)
331
332
    def test_filerename_path_checking(self):
333
        self.assertRaises(ValueError, commands.FileRenameCommand, "", "foo")
334
        self.assertRaises(ValueError, commands.FileRenameCommand, None, "foo")
335
        self.assertRaises(ValueError, commands.FileRenameCommand, "foo", "")
336
        self.assertRaises(ValueError, commands.FileRenameCommand, "foo", None)
337
338
    def test_filecopy_path_checking(self):
339
        self.assertRaises(ValueError, commands.FileCopyCommand, "", "foo")
340
        self.assertRaises(ValueError, commands.FileCopyCommand, None, "foo")
341
        self.assertRaises(ValueError, commands.FileCopyCommand, "foo", "")
342
        self.assertRaises(ValueError, commands.FileCopyCommand, "foo", None)