1 # Copyright (C) 2009 Canonical Ltd
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """Test how Commands are displayed"""
18 from unittest import TestCase
20 from fastimport import (
25 class TestBlobDisplay(TestCase):
28 c = commands.BlobCommand("1", "hello world")
29 self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c))
31 def test_blob_no_mark(self):
32 c = commands.BlobCommand(None, "hello world")
33 self.assertEqual("blob\ndata 11\nhello world", repr(c))
36 class TestCheckpointDisplay(TestCase):
38 def test_checkpoint(self):
39 c = commands.CheckpointCommand()
40 self.assertEqual("checkpoint", repr(c))
43 class TestCommitDisplay(TestCase):
45 def test_commit(self):
46 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
47 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
48 c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
49 "release v1.0", ":aaa", None, None)
51 "commit refs/heads/master\n"
53 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
59 def test_commit_unicode_committer(self):
60 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
61 name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'
62 name_utf8 = name.encode('utf8')
63 committer = (name, 'test@example.com', 1234567890, -6 * 3600)
64 c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
65 "release v1.0", ":aaa", None, None)
67 "commit refs/heads/master\n"
69 "committer %s <test@example.com> 1234567890 -0600\n"
72 "from :aaa" % (name_utf8,),
75 def test_commit_no_mark(self):
76 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
77 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
78 c = commands.CommitCommand("refs/heads/master", None, None, committer,
79 "release v1.0", ":aaa", None, None)
81 "commit refs/heads/master\n"
82 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
88 def test_commit_no_from(self):
89 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
90 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
91 c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
92 "release v1.0", None, None, None)
94 "commit refs/heads/master\n"
96 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
101 def test_commit_with_author(self):
102 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
103 author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
104 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
105 c = commands.CommitCommand("refs/heads/master", "bbb", author,
106 committer, "release v1.0", ":aaa", None, None)
108 "commit refs/heads/master\n"
110 "author Sue Wong <sue@example.com> 1234565432 -0600\n"
111 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
117 def test_commit_with_merges(self):
118 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
119 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
120 c = commands.CommitCommand("refs/heads/master", "ddd", None, committer,
121 "release v1.0", ":aaa", [':bbb', ':ccc'], None)
123 "commit refs/heads/master\n"
125 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
133 def test_commit_with_filecommands(self):
135 commands.FileDeleteCommand('readme.txt'),
136 commands.FileModifyCommand('NEWS', 0100644, None,
139 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
140 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
141 c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
142 "release v1.0", ":aaa", None, file_cmds)
144 "commit refs/heads/master\n"
146 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
151 "M 644 inline NEWS\n"
156 def test_commit_with_more_authors(self):
157 # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
158 author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
159 committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
161 ('Al Smith', 'al@example.com', 1234565432, -6 * 3600),
162 ('Bill Jones', 'bill@example.com', 1234565432, -6 * 3600),
164 c = commands.CommitCommand("refs/heads/master", "bbb", author,
165 committer, "release v1.0", ":aaa", None, None,
166 more_authors=more_authors)
168 "commit refs/heads/master\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"
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)
183 u'greeting': u'hello',
186 c = commands.CommitCommand("refs/heads/master", "bbb", None,
187 committer, "release v1.0", ":aaa", None, None,
188 properties=properties)
190 "commit refs/heads/master\n"
192 "committer Joe Wong <joe@example.com> 1234567890 -0600\n"
196 "property greeting 5 hello\n"
197 "property planet 5 world",
201 class TestFeatureDisplay(TestCase):
203 def test_feature(self):
204 c = commands.FeatureCommand("dwim")
205 self.assertEqual("feature dwim", repr(c))
207 def test_feature_with_value(self):
208 c = commands.FeatureCommand("dwim", "please")
209 self.assertEqual("feature dwim=please", repr(c))
212 class TestProgressDisplay(TestCase):
214 def test_progress(self):
215 c = commands.ProgressCommand("doing foo")
216 self.assertEqual("progress doing foo", repr(c))
219 class TestResetDisplay(TestCase):
221 def test_reset(self):
222 c = commands.ResetCommand("refs/tags/v1.0", ":xxx")
223 self.assertEqual("reset refs/tags/v1.0\nfrom :xxx\n", repr(c))
225 def test_reset_no_from(self):
226 c = commands.ResetCommand("refs/remotes/origin/master", None)
227 self.assertEqual("reset refs/remotes/origin/master", repr(c))
230 class TestTagDisplay(TestCase):
233 # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
234 tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
235 c = commands.TagCommand("refs/tags/v1.0", ":xxx", tagger, "create v1.0")
237 "tag refs/tags/v1.0\n"
239 "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
244 def test_tag_no_from(self):
245 tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
246 c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
248 "tag refs/tags/v1.0\n"
249 "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
255 class TestFileModifyDisplay(TestCase):
257 def test_filemodify_file(self):
258 c = commands.FileModifyCommand("foo/bar", 0100644, ":23", None)
259 self.assertEqual("M 644 :23 foo/bar", repr(c))
261 def test_filemodify_file_executable(self):
262 c = commands.FileModifyCommand("foo/bar", 0100755, ":23", None)
263 self.assertEqual("M 755 :23 foo/bar", repr(c))
265 def test_filemodify_file_internal(self):
266 c = commands.FileModifyCommand("foo/bar", 0100644, None,
268 self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
270 def test_filemodify_symlink(self):
271 c = commands.FileModifyCommand("foo/bar", 0120000, None, "baz")
272 self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
274 def test_filemodify_treeref(self):
275 c = commands.FileModifyCommand("tree-info", 0160000,
276 "revision-id-info", None)
277 self.assertEqual("M 160000 revision-id-info tree-info", repr(c))
280 class TestFileDeleteDisplay(TestCase):
282 def test_filedelete(self):
283 c = commands.FileDeleteCommand("foo/bar")
284 self.assertEqual("D foo/bar", repr(c))
287 class TestFileCopyDisplay(TestCase):
289 def test_filecopy(self):
290 c = commands.FileCopyCommand("foo/bar", "foo/baz")
291 self.assertEqual("C foo/bar foo/baz", repr(c))
293 def test_filecopy_quoted(self):
294 # Check the first path is quoted if it contains spaces
295 c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
296 self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
299 class TestFileRenameDisplay(TestCase):
301 def test_filerename(self):
302 c = commands.FileRenameCommand("foo/bar", "foo/baz")
303 self.assertEqual("R foo/bar foo/baz", repr(c))
305 def test_filerename_quoted(self):
306 # Check the first path is quoted if it contains spaces
307 c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
308 self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
311 class TestFileDeleteAllDisplay(TestCase):
313 def test_filedeleteall(self):
314 c = commands.FileDeleteAllCommand()
315 self.assertEqual("deleteall", repr(c))
318 class TestPathChecking(TestCase):
320 def test_filemodify_path_checking(self):
321 self.assertRaises(ValueError, commands.FileModifyCommand, "",
322 0100644, None, "text")
323 self.assertRaises(ValueError, commands.FileModifyCommand, None,
324 0100644, None, "text")
326 def test_filedelete_path_checking(self):
327 self.assertRaises(ValueError, commands.FileDeleteCommand, "")
328 self.assertRaises(ValueError, commands.FileDeleteCommand, None)
330 def test_filerename_path_checking(self):
331 self.assertRaises(ValueError, commands.FileRenameCommand, "", "foo")
332 self.assertRaises(ValueError, commands.FileRenameCommand, None, "foo")
333 self.assertRaises(ValueError, commands.FileRenameCommand, "foo", "")
334 self.assertRaises(ValueError, commands.FileRenameCommand, "foo", None)
336 def test_filecopy_path_checking(self):
337 self.assertRaises(ValueError, commands.FileCopyCommand, "", "foo")
338 self.assertRaises(ValueError, commands.FileCopyCommand, None, "foo")
339 self.assertRaises(ValueError, commands.FileCopyCommand, "foo", "")
340 self.assertRaises(ValueError, commands.FileCopyCommand, "foo", None)