summaryrefslogtreecommitdiff
path: root/fastimport/tests/test_commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'fastimport/tests/test_commands.py')
-rw-r--r--fastimport/tests/test_commands.py139
1 files changed, 80 insertions, 59 deletions
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index ccae34a..dabd6a7 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -18,7 +18,6 @@
from unittest import TestCase
from fastimport.helpers import (
- repr_bytes,
utf8_bytes_string,
)
@@ -31,18 +30,18 @@ class TestBlobDisplay(TestCase):
def test_blob(self):
c = commands.BlobCommand(b"1", b"hello world")
- self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", repr_bytes(c))
+ self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", bytes(c))
def test_blob_no_mark(self):
c = commands.BlobCommand(None, b"hello world")
- self.assertEqual(b"blob\ndata 11\nhello world", repr_bytes(c))
+ self.assertEqual(b"blob\ndata 11\nhello world", bytes(c))
class TestCheckpointDisplay(TestCase):
def test_checkpoint(self):
c = commands.CheckpointCommand()
- self.assertEqual(b'checkpoint', repr_bytes(c))
+ self.assertEqual(b'checkpoint', bytes(c))
class TestCommitDisplay(TestCase):
@@ -50,7 +49,8 @@ class TestCommitDisplay(TestCase):
def test_commit(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b"refs/heads/master", b"bbb", None, committer,
+ c = commands.CommitCommand(
+ b"refs/heads/master", b"bbb", None, committer,
b"release v1.0", b":aaa", None, None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -59,7 +59,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_unicode_committer(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -75,28 +75,31 @@ class TestCommitDisplay(TestCase):
)
committer = (name, b'test@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None, committer,
b'release v1.0', b':aaa', None, None)
- self.assertEqual(commit_utf8, repr_bytes(c))
+ self.assertEqual(commit_utf8, bytes(c))
def test_commit_no_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', None, None, committer,
- b'release v1.0', b':aaa', None, None)
+ c = commands.CommitCommand(
+ b'refs/heads/master', None, None, committer,
+ b'release v1.0', b':aaa', None, None)
self.assertEqual(
b"commit refs/heads/master\n"
b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_no_from(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b"refs/heads/master", b"bbb", None, committer,
+ c = commands.CommitCommand(
+ b"refs/heads/master", b"bbb", None, committer,
b"release v1.0", None, None, None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -104,13 +107,14 @@ class TestCommitDisplay(TestCase):
b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 12\n"
b"release v1.0",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_author(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
author = (b'Sue Wong', b'sue@example.com', 1234565432, -6 * 3600)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', author,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', author,
committer, b'release v1.0', b':aaa', None, None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -120,12 +124,13 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_merges(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b"refs/heads/master", b"ddd", None, committer,
+ c = commands.CommitCommand(
+ b"refs/heads/master", b"ddd", None, committer,
b'release v1.0', b":aaa", [b':bbb', b':ccc'], None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -136,17 +141,18 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"merge :bbb\n"
b"merge :ccc",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_filecommands(self):
file_cmds = iter([
commands.FileDeleteCommand(b'readme.txt'),
- commands.FileModifyCommand(b'NEWS', 0o100644, None,
- b'blah blah blah'),
+ commands.FileModifyCommand(
+ b'NEWS', 0o100644, None, b'blah blah blah'),
])
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None, committer,
b'release v1.0', b':aaa', None, file_cmds)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -159,7 +165,7 @@ class TestCommitDisplay(TestCase):
b"M 644 inline NEWS\n"
b"data 14\n"
b"blah blah blah",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_more_authors(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -169,7 +175,8 @@ class TestCommitDisplay(TestCase):
(b'Al Smith', b'al@example.com', 1234565432, -6 * 3600),
(b'Bill Jones', b'bill@example.com', 1234565432, -6 * 3600),
]
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', author,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', author,
committer, b'release v1.0', b':aaa', None, None,
more_authors=more_authors)
self.assertEqual(
@@ -182,7 +189,7 @@ class TestCommitDisplay(TestCase):
b"data 12\n"
b"release v1.0\n"
b"from :aaa",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_properties(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -191,7 +198,8 @@ class TestCommitDisplay(TestCase):
u'greeting': u'hello',
u'planet': u'world',
}
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', None,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None,
committer, b'release v1.0', b':aaa', None, None,
properties=properties)
self.assertEqual(
@@ -203,7 +211,7 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"property greeting 5 hello\n"
b"property planet 5 world",
- repr_bytes(c))
+ bytes(c))
def test_commit_with_int_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
@@ -212,7 +220,8 @@ class TestCommitDisplay(TestCase):
u'greeting': u'hello',
u'planet': u'world',
}
- c = commands.CommitCommand(b'refs/heads/master', 123, None,
+ c = commands.CommitCommand(
+ b'refs/heads/master', 123, None,
committer, b'release v1.0', b':aaa', None, None,
properties=properties)
self.assertEqual(
@@ -224,7 +233,8 @@ class TestCommitDisplay(TestCase):
b"from :aaa\n"
b"property greeting 5 hello\n"
b"property planet 5 world",
- repr_bytes(c))
+ bytes(c))
+
class TestCommitCopy(TestCase):
@@ -232,7 +242,8 @@ class TestCommitCopy(TestCase):
super(TestCommitCopy, self).setUp()
file_cmds = iter([
commands.FileDeleteCommand(b'readme.txt'),
- commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'),
+ commands.FileModifyCommand(
+ b'NEWS', 0o100644, None, b'blah blah blah'),
])
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
@@ -244,45 +255,46 @@ class TestCommitCopy(TestCase):
c2 = self.c.copy()
self.assertFalse(self.c is c2)
- self.assertEqual(repr_bytes(self.c), repr_bytes(c2))
+ self.assertEqual(bytes(self.c), bytes(c2))
def test_replace_attr(self):
c2 = self.c.copy(mark=b'ccc')
self.assertEqual(
- repr_bytes(self.c).replace(b'mark :bbb', b'mark :ccc'),
- repr_bytes(c2)
+ bytes(self.c).replace(b'mark :bbb', b'mark :ccc'),
+ bytes(c2)
)
def test_invalid_attribute(self):
self.assertRaises(TypeError, self.c.copy, invalid=True)
+
class TestFeatureDisplay(TestCase):
def test_feature(self):
c = commands.FeatureCommand(b"dwim")
- self.assertEqual(b"feature dwim", repr_bytes(c))
+ self.assertEqual(b"feature dwim", bytes(c))
def test_feature_with_value(self):
c = commands.FeatureCommand(b"dwim", b"please")
- self.assertEqual(b"feature dwim=please", repr_bytes(c))
+ self.assertEqual(b"feature dwim=please", bytes(c))
class TestProgressDisplay(TestCase):
def test_progress(self):
c = commands.ProgressCommand(b"doing foo")
- self.assertEqual(b"progress doing foo", repr_bytes(c))
+ self.assertEqual(b"progress doing foo", bytes(c))
class TestResetDisplay(TestCase):
def test_reset(self):
c = commands.ResetCommand(b"refs/tags/v1.0", b":xxx")
- self.assertEqual(b"reset refs/tags/v1.0\nfrom :xxx\n", repr_bytes(c))
+ self.assertEqual(b"reset refs/tags/v1.0\nfrom :xxx\n", bytes(c))
def test_reset_no_from(self):
c = commands.ResetCommand(b'refs/remotes/origin/master', None)
- self.assertEqual(b'reset refs/remotes/origin/master', repr_bytes(c))
+ self.assertEqual(b'reset refs/remotes/origin/master', bytes(c))
class TestTagDisplay(TestCase):
@@ -290,93 +302,100 @@ class TestTagDisplay(TestCase):
def test_tag(self):
# tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
tagger = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.TagCommand(b'refs/tags/v1.0', b':xxx', tagger, b'create v1.0')
+ c = commands.TagCommand(
+ b'refs/tags/v1.0', b':xxx', tagger, b'create v1.0')
self.assertEqual(
b"tag refs/tags/v1.0\n"
b"from :xxx\n"
b"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 11\n"
b"create v1.0",
- repr_bytes(c))
+ bytes(c))
def test_tag_no_from(self):
tagger = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.TagCommand(b'refs/tags/v1.0', None, tagger, b'create v1.0')
+ c = commands.TagCommand(
+ b'refs/tags/v1.0', None, tagger, b'create v1.0')
self.assertEqual(
b"tag refs/tags/v1.0\n"
b"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
b"data 11\n"
b"create v1.0",
- repr_bytes(c))
+ bytes(c))
class TestFileModifyDisplay(TestCase):
def test_filemodify_file(self):
c = commands.FileModifyCommand(b'foo/bar', 0o100644, b':23', None)
- self.assertEqual(b'M 644 :23 foo/bar', repr_bytes(c))
+ self.assertEqual(b'M 644 :23 foo/bar', bytes(c))
def test_filemodify_file_executable(self):
c = commands.FileModifyCommand(b'foo/bar', 0o100755, b':23', None)
- self.assertEqual(b'M 755 :23 foo/bar', repr_bytes(c))
+ self.assertEqual(b'M 755 :23 foo/bar', bytes(c))
def test_filemodify_file_internal(self):
- c = commands.FileModifyCommand(b'foo/bar', 0o100644, None,
- b'hello world')
- self.assertEqual(b'M 644 inline foo/bar\ndata 11\nhello world', repr_bytes(c))
+ c = commands.FileModifyCommand(
+ b'foo/bar', 0o100644, None, b'hello world')
+ self.assertEqual(
+ b'M 644 inline foo/bar\ndata 11\nhello world', bytes(c))
def test_filemodify_symlink(self):
c = commands.FileModifyCommand(b'foo/bar', 0o120000, None, b'baz')
- self.assertEqual(b'M 120000 inline foo/bar\ndata 3\nbaz', repr_bytes(c))
+ self.assertEqual(
+ b'M 120000 inline foo/bar\ndata 3\nbaz', bytes(c))
def test_filemodify_treeref(self):
- c = commands.FileModifyCommand(b'tree-info', 0o160000,
- b'revision-id-info', None)
- self.assertEqual(b'M 160000 revision-id-info tree-info', repr_bytes(c))
+ c = commands.FileModifyCommand(
+ b'tree-info', 0o160000, b'revision-id-info', None)
+ self.assertEqual(
+ b'M 160000 revision-id-info tree-info', bytes(c))
class TestFileDeleteDisplay(TestCase):
def test_filedelete(self):
c = commands.FileDeleteCommand(b'foo/bar')
- self.assertEqual(b'D foo/bar', repr_bytes(c))
+ self.assertEqual(b'D foo/bar', bytes(c))
class TestFileCopyDisplay(TestCase):
def test_filecopy(self):
c = commands.FileCopyCommand(b'foo/bar', b'foo/baz')
- self.assertEqual(b'C foo/bar foo/baz', repr_bytes(c))
+ self.assertEqual(b'C foo/bar foo/baz', bytes(c))
def test_filecopy_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileCopyCommand(b'foo/b a r', b'foo/b a z')
- self.assertEqual(b'C "foo/b a r" foo/b a z', repr_bytes(c))
+ self.assertEqual(b'C "foo/b a r" foo/b a z', bytes(c))
class TestFileRenameDisplay(TestCase):
def test_filerename(self):
c = commands.FileRenameCommand(b'foo/bar', b'foo/baz')
- self.assertEqual(b'R foo/bar foo/baz', repr_bytes(c))
+ self.assertEqual(b'R foo/bar foo/baz', bytes(c))
def test_filerename_quoted(self):
# Check the first path is quoted if it contains spaces
c = commands.FileRenameCommand(b'foo/b a r', b'foo/b a z')
- self.assertEqual(b'R "foo/b a r" foo/b a z', repr_bytes(c))
+ self.assertEqual(b'R "foo/b a r" foo/b a z', bytes(c))
class TestFileDeleteAllDisplay(TestCase):
def test_filedeleteall(self):
c = commands.FileDeleteAllCommand()
- self.assertEqual(b'deleteall', repr_bytes(c))
+ self.assertEqual(b'deleteall', bytes(c))
+
class TestNotesDisplay(TestCase):
def test_noteonly(self):
c = commands.NoteModifyCommand(b'foo', b'A basic note')
- self.assertEqual(b'N inline :foo\ndata 12\nA basic note', repr_bytes(c))
+ self.assertEqual(
+ b'N inline :foo\ndata 12\nA basic note', bytes(c))
def test_notecommit(self):
committer = (b'Ed Mund', b'ed@example.org', 1234565432, 0)
@@ -443,15 +462,17 @@ Notes added by 'git notes add'
N inline :1
data 10
Test test
-""", b''.join([repr_bytes(s) for s in commits]))
+""", b''.join([bytes(s) for s in commits]))
class TestPathChecking(TestCase):
def test_filemodify_path_checking(self):
- self.assertRaises(ValueError, commands.FileModifyCommand, b'',
+ self.assertRaises(
+ ValueError, commands.FileModifyCommand, b'',
0o100644, None, b'text')
- self.assertRaises(ValueError, commands.FileModifyCommand, None,
+ self.assertRaises(
+ ValueError, commands.FileModifyCommand, None,
0o100644, None, b'text')
def test_filedelete_path_checking(self):