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, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test how Commands are displayed"""
19
from bzrlib import tests
21
from bzrlib.plugins.fastimport import (
26
class TestBlobDisplay(tests.TestCase):
29
c = commands.BlobCommand("1", "hello world")
30
self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c))
32
def test_blob_no_mark(self):
33
c = commands.BlobCommand(None, "hello world")
34
self.assertEqual("blob\ndata 11\nhello world", repr(c))
37
class TestCheckpointDisplay(tests.TestCase):
39
def test_checkpoint(self):
40
c = commands.CheckpointCommand()
41
self.assertEqual("checkpoint", repr(c))
44
class TestCommitDisplay(tests.TestCase):
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,
50
"release v1.0", "aaa", None, None)
52
"commit refs/heads/master\n"
54
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
60
def test_commit_no_mark(self):
61
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
62
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
63
c = commands.CommitCommand("refs/heads/master", None, None, committer,
64
"release v1.0", "aaa", None, None)
66
"commit refs/heads/master\n"
67
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
73
def test_commit_no_from(self):
74
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
75
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
76
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
77
"release v1.0", None, None, None)
79
"commit refs/heads/master\n"
81
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
86
def test_commit_with_author(self):
87
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
88
author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
89
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
90
c = commands.CommitCommand("refs/heads/master", "bbb", author,
91
committer, "release v1.0", "aaa", None, None)
93
"commit refs/heads/master\n"
95
"author Sue Wong <sue@example.com> 1234565432 -0600\n"
96
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
102
def test_commit_with_merges(self):
103
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
104
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
105
c = commands.CommitCommand("refs/heads/master", "ddd", None, committer,
106
"release v1.0", "aaa", ['bbb', 'ccc'], None)
107
self.assertEqualDiff(
108
"commit refs/heads/master\n"
110
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
118
def test_commit_with_filecommands(self):
120
commands.FileDeleteCommand('readme.txt'),
121
commands.FileModifyCommand('NEWS', 'file', False, None,
124
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
125
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
126
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
127
"release v1.0", "aaa", None, file_cmds)
128
self.assertEqualDiff(
129
"commit refs/heads/master\n"
131
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
136
"M 644 inline NEWS\n"
142
class TestProgressDisplay(tests.TestCase):
144
def test_progress(self):
145
c = commands.ProgressCommand("doing foo")
146
self.assertEqual("progress doing foo", repr(c))
149
class TestResetDisplay(tests.TestCase):
151
def test_reset(self):
152
c = commands.ResetCommand("refs/tags/v1.0", "xxx")
153
self.assertEqual("reset refs/tags/v1.0\nfrom :xxx", repr(c))
155
def test_reset_no_from(self):
156
c = commands.ResetCommand("refs/remotes/origin/master", None)
157
self.assertEqual("reset refs/remotes/origin/master", repr(c))
160
class TestTagDisplay(tests.TestCase):
163
# tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
164
tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
165
c = commands.TagCommand("refs/tags/v1.0", "xxx", tagger, "create v1.0")
167
"tag refs/tags/v1.0\n"
169
"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
174
def test_tag_no_from(self):
175
tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
176
c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
177
self.assertEqualDiff(
178
"tag refs/tags/v1.0\n"
179
"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
185
class TestFileModifyDisplay(tests.TestCase):
187
def test_filemodify_file(self):
188
c = commands.FileModifyCommand("foo/bar", "file", False, "23", None)
189
self.assertEqual("M 644 :23 foo/bar", repr(c))
191
def test_filemodify_file_executable(self):
192
c = commands.FileModifyCommand("foo/bar", "file", True, "23", None)
193
self.assertEqual("M 755 :23 foo/bar", repr(c))
195
def test_filemodify_file_internal(self):
196
c = commands.FileModifyCommand("foo/bar", "file", False, None,
198
self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
200
def test_filemodify_symlink(self):
201
c = commands.FileModifyCommand("foo/bar", "symlink", False, None, "baz")
202
self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
205
class TestFileDeleteDisplay(tests.TestCase):
207
def test_filedelete(self):
208
c = commands.FileDeleteCommand("foo/bar")
209
self.assertEqual("D foo/bar", repr(c))
212
class TestFileCopyDisplay(tests.TestCase):
214
def test_filecopy(self):
215
c = commands.FileCopyCommand("foo/bar", "foo/baz")
216
self.assertEqual("C foo/bar foo/baz", repr(c))
218
def test_filecopy_quoted(self):
219
# Check the first path is quoted if it contains spaces
220
c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
221
self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
224
class TestFileRenameDisplay(tests.TestCase):
226
def test_filerename(self):
227
c = commands.FileRenameCommand("foo/bar", "foo/baz")
228
self.assertEqual("R foo/bar foo/baz", repr(c))
230
def test_filerename_quoted(self):
231
# Check the first path is quoted if it contains spaces
232
c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
233
self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
236
class TestFileDeleteAllDisplay(tests.TestCase):
238
def test_filedeleteall(self):
239
c = commands.FileDeleteAllCommand()
240
self.assertEqual("deleteall", repr(c))