1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
# Copyright (C) 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test how Commands are displayed"""
from testtools import TestCase
from fastimport import (
commands,
)
class TestBlobDisplay(TestCase):
def test_blob(self):
c = commands.BlobCommand("1", "hello world")
self.assertEqual("blob\nmark :1\ndata 11\nhello world", repr(c))
def test_blob_no_mark(self):
c = commands.BlobCommand(None, "hello world")
self.assertEqual("blob\ndata 11\nhello world", repr(c))
class TestCheckpointDisplay(TestCase):
def test_checkpoint(self):
c = commands.CheckpointCommand()
self.assertEqual("checkpoint", repr(c))
class TestCommitDisplay(TestCase):
def test_commit(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
"release v1.0", ":aaa", None, None)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa",
repr(c))
def test_commit_unicode_committer(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'
name_utf8 = name.encode('utf8')
committer = (name, 'test@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
"release v1.0", ":aaa", None, None)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"committer %s <test@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa" % (name_utf8,),
repr(c))
def test_commit_no_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", None, None, committer,
"release v1.0", ":aaa", None, None)
self.assertEqual(
"commit refs/heads/master\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa",
repr(c))
def test_commit_no_from(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
"release v1.0", None, None, None)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0",
repr(c))
def test_commit_with_author(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", author,
committer, "release v1.0", ":aaa", None, None)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"author Sue Wong <sue@example.com> 1234565432 -0600\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa",
repr(c))
def test_commit_with_merges(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "ddd", None, committer,
"release v1.0", ":aaa", [':bbb', ':ccc'], None)
self.assertEqual(
"commit refs/heads/master\n"
"mark :ddd\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa\n"
"merge :bbb\n"
"merge :ccc",
repr(c))
def test_commit_with_filecommands(self):
file_cmds = iter([
commands.FileDeleteCommand('readme.txt'),
commands.FileModifyCommand('NEWS', 0100644, None,
'blah blah blah'),
])
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
"release v1.0", ":aaa", None, file_cmds)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa\n"
"D readme.txt\n"
"M 644 inline NEWS\n"
"data 14\n"
"blah blah blah",
repr(c))
def test_commit_with_more_authors(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
author = ('Sue Wong', 'sue@example.com', 1234565432, -6 * 3600)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
more_authors = [
('Al Smith', 'al@example.com', 1234565432, -6 * 3600),
('Bill Jones', 'bill@example.com', 1234565432, -6 * 3600),
]
c = commands.CommitCommand("refs/heads/master", "bbb", author,
committer, "release v1.0", ":aaa", None, None,
more_authors=more_authors)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"author Sue Wong <sue@example.com> 1234565432 -0600\n"
"author Al Smith <al@example.com> 1234565432 -0600\n"
"author Bill Jones <bill@example.com> 1234565432 -0600\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa",
repr(c))
def test_commit_with_properties(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
properties = {
u'greeting': u'hello',
u'planet': u'world',
}
c = commands.CommitCommand("refs/heads/master", "bbb", None,
committer, "release v1.0", ":aaa", None, None,
properties=properties)
self.assertEqual(
"commit refs/heads/master\n"
"mark :bbb\n"
"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 12\n"
"release v1.0\n"
"from :aaa\n"
"property greeting 5 hello\n"
"property planet 5 world",
repr(c))
class TestFeatureDisplay(TestCase):
def test_feature(self):
c = commands.FeatureCommand("dwim")
self.assertEqual("feature dwim", repr(c))
def test_feature_with_value(self):
c = commands.FeatureCommand("dwim", "please")
self.assertEqual("feature dwim=please", repr(c))
class TestProgressDisplay(TestCase):
def test_progress(self):
c = commands.ProgressCommand("doing foo")
self.assertEqual("progress doing foo", repr(c))
class TestResetDisplay(TestCase):
def test_reset(self):
c = commands.ResetCommand("refs/tags/v1.0", ":xxx")
self.assertEqual("reset refs/tags/v1.0\nfrom :xxx\n", repr(c))
def test_reset_no_from(self):
c = commands.ResetCommand("refs/remotes/origin/master", None)
self.assertEqual("reset refs/remotes/origin/master", repr(c))
class TestTagDisplay(TestCase):
def test_tag(self):
# tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.TagCommand("refs/tags/v1.0", ":xxx", tagger, "create v1.0")
self.assertEqual(
"tag refs/tags/v1.0\n"
"from :xxx\n"
"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 11\n"
"create v1.0",
repr(c))
def test_tag_no_from(self):
tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600)
c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0")
self.assertEqual(
"tag refs/tags/v1.0\n"
"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
"data 11\n"
"create v1.0",
repr(c))
class TestFileModifyDisplay(TestCase):
def test_filemodify_file(self):
c = commands.FileModifyCommand("foo/bar", 0100644, ":23", None)
self.assertEqual("M 644 :23 foo/bar", repr(c))
def test_filemodify_file_executable(self):
c = commands.FileModifyCommand("foo/bar", 0100755, ":23", None)
self.assertEqual("M 755 :23 foo/bar", repr(c))
def test_filemodify_file_internal(self):
c = commands.FileModifyCommand("foo/bar", 0100644, None,
"hello world")
self.assertEqual("M 644 inline foo/bar\ndata 11\nhello world", repr(c))
def test_filemodify_symlink(self):
c = commands.FileModifyCommand("foo/bar", 0120000, None, "baz")
self.assertEqual("M 120000 inline foo/bar\ndata 3\nbaz", repr(c))
def test_filemodify_treeref(self):
c = commands.FileModifyCommand("tree-info", 0160000,
"revision-id-info", None)
self.assertEqual("M 160000 revision-id-info tree-info", repr(c))
class TestFileDeleteDisplay(TestCase):
def test_filedelete(self):
c = commands.FileDeleteCommand("foo/bar")
self.assertEqual("D foo/bar", repr(c))
class TestFileCopyDisplay(TestCase):
def test_filecopy(self):
c = commands.FileCopyCommand("foo/bar", "foo/baz")
self.assertEqual("C foo/bar foo/baz", repr(c))
def test_filecopy_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileCopyCommand("foo/b a r", "foo/b a z")
self.assertEqual('C "foo/b a r" foo/b a z', repr(c))
class TestFileRenameDisplay(TestCase):
def test_filerename(self):
c = commands.FileRenameCommand("foo/bar", "foo/baz")
self.assertEqual("R foo/bar foo/baz", repr(c))
def test_filerename_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileRenameCommand("foo/b a r", "foo/b a z")
self.assertEqual('R "foo/b a r" foo/b a z', repr(c))
class TestFileDeleteAllDisplay(TestCase):
def test_filedeleteall(self):
c = commands.FileDeleteAllCommand()
self.assertEqual("deleteall", repr(c))
class TestPathChecking(TestCase):
def test_filemodify_path_checking(self):
self.assertRaises(ValueError, commands.FileModifyCommand, "",
0100644, None, "text")
self.assertRaises(ValueError, commands.FileModifyCommand, None,
0100644, None, "text")
def test_filedelete_path_checking(self):
self.assertRaises(ValueError, commands.FileDeleteCommand, "")
self.assertRaises(ValueError, commands.FileDeleteCommand, None)
def test_filerename_path_checking(self):
self.assertRaises(ValueError, commands.FileRenameCommand, "", "foo")
self.assertRaises(ValueError, commands.FileRenameCommand, None, "foo")
self.assertRaises(ValueError, commands.FileRenameCommand, "foo", "")
self.assertRaises(ValueError, commands.FileRenameCommand, "foo", None)
def test_filecopy_path_checking(self):
self.assertRaises(ValueError, commands.FileCopyCommand, "", "foo")
self.assertRaises(ValueError, commands.FileCopyCommand, None, "foo")
self.assertRaises(ValueError, commands.FileCopyCommand, "foo", "")
self.assertRaises(ValueError, commands.FileCopyCommand, "foo", None)
|