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