summaryrefslogtreecommitdiffstats
path: root/qa/test_commits.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:08 +0000
commit3313b4f9c3c5d6a579588e77068ca3ae3edffe2b (patch)
tree81fccb2a4db79b0de9b0d64701581add3a9a1d21 /qa/test_commits.py
parentAdding upstream version 0.14.0. (diff)
downloadgitlint-3313b4f9c3c5d6a579588e77068ca3ae3edffe2b.tar.xz
gitlint-3313b4f9c3c5d6a579588e77068ca3ae3edffe2b.zip
Adding upstream version 0.15.0.upstream/0.15.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/test_commits.py')
-rw-r--r--qa/test_commits.py51
1 files changed, 25 insertions, 26 deletions
diff --git a/qa/test_commits.py b/qa/test_commits.py
index f485856..389ad66 100644
--- a/qa/test_commits.py
+++ b/qa/test_commits.py
@@ -6,7 +6,6 @@ import arrow
from qa.shell import echo, git, gitlint
from qa.base import BaseTestCase
-from qa.utils import sstr
class CommitsTests(BaseTestCase):
@@ -16,10 +15,10 @@ class CommitsTests(BaseTestCase):
def test_successful(self):
""" Test linting multiple commits without violations """
git("checkout", "-b", "test-branch-commits-base", _cwd=self.tmp_git_repo)
- self.create_simple_commit(u"Sïmple title\n\nSimple bödy describing the commit")
+ self.create_simple_commit("Sïmple title\n\nSimple bödy describing the commit")
git("checkout", "-b", "test-branch-commits", _cwd=self.tmp_git_repo)
- self.create_simple_commit(u"Sïmple title2\n\nSimple bödy describing the commit2")
- self.create_simple_commit(u"Sïmple title3\n\nSimple bödy describing the commit3")
+ self.create_simple_commit("Sïmple title2\n\nSimple bödy describing the commit2")
+ self.create_simple_commit("Sïmple title3\n\nSimple bödy describing the commit3")
output = gitlint("--commits", "test-branch-commits-base...test-branch-commits",
_cwd=self.tmp_git_repo, _tty_in=True)
self.assertEqualStdout(output, "")
@@ -27,12 +26,12 @@ class CommitsTests(BaseTestCase):
def test_violations(self):
""" Test linting multiple commits with violations """
git("checkout", "-b", "test-branch-commits-violations-base", _cwd=self.tmp_git_repo)
- self.create_simple_commit(u"Sïmple title.\n")
+ self.create_simple_commit("Sïmple title.\n")
git("checkout", "-b", "test-branch-commits-violations", _cwd=self.tmp_git_repo)
- self.create_simple_commit(u"Sïmple title2.\n")
+ self.create_simple_commit("Sïmple title2.\n")
commit_sha1 = self.get_last_commit_hash()[:10]
- self.create_simple_commit(u"Sïmple title3.\n")
+ self.create_simple_commit("Sïmple title3.\n")
commit_sha2 = self.get_last_commit_hash()[:10]
output = gitlint("--commits", "test-branch-commits-violations-base...test-branch-commits-violations",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4])
@@ -43,14 +42,14 @@ class CommitsTests(BaseTestCase):
def test_lint_single_commit(self):
""" Tests `gitlint --commits <sha>` """
- self.create_simple_commit(u"Sïmple title.\n")
- self.create_simple_commit(u"Sïmple title2.\n")
+ self.create_simple_commit("Sïmple title.\n")
+ self.create_simple_commit("Sïmple title2.\n")
commit_sha = self.get_last_commit_hash()
- refspec = "{0}^...{0}".format(commit_sha)
- self.create_simple_commit(u"Sïmple title3.\n")
+ refspec = f"{commit_sha}^...{commit_sha}"
+ self.create_simple_commit("Sïmple title3.\n")
output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
- expected = (u"1: T3 Title has trailing punctuation (.): \"Sïmple title2.\"\n" +
- u"3: B6 Body message is missing\n")
+ expected = ("1: T3 Title has trailing punctuation (.): \"Sïmple title2.\"\n" +
+ "3: B6 Body message is missing\n")
self.assertEqual(output.exit_code, 2)
self.assertEqualStdout(output, expected)
@@ -61,7 +60,7 @@ class CommitsTests(BaseTestCase):
echo "WIP: Pïpe test." | gitlint --staged --debug
"""
# Create a commit first, before we stage changes. This ensures the repo is properly initialized.
- self.create_simple_commit(u"Sïmple title.\n")
+ self.create_simple_commit("Sïmple title.\n")
# Add some files, stage them: they should show up in the debug output as changed file
filename1 = self.create_file(self.tmp_git_repo)
@@ -69,12 +68,12 @@ class CommitsTests(BaseTestCase):
filename2 = self.create_file(self.tmp_git_repo)
git("add", filename2, _cwd=self.tmp_git_repo)
- output = gitlint(echo(u"WIP: Pïpe test."), "--staged", "--debug",
+ output = gitlint(echo("WIP: Pïpe test."), "--staged", "--debug",
_cwd=self.tmp_git_repo, _tty_in=False, _err_to_out=True, _ok_code=[3])
# Determine variable parts of expected output
expected_kwargs = self.get_debug_vars_last_commit()
- expected_kwargs.update({'changed_files': sstr(sorted([filename1, filename2]))})
+ expected_kwargs.update({'changed_files': sorted([filename1, filename2])})
# It's not really possible to determine the "Date: ..." line that is part of the debug output as this date
# is not taken from git but instead generated by gitlint itself. As a workaround, we extract the date from the
@@ -95,7 +94,7 @@ class CommitsTests(BaseTestCase):
gitlint --msg-filename /tmp/my-commit-msg --staged --debug
"""
# Create a commit first, before we stage changes. This ensures the repo is properly initialized.
- self.create_simple_commit(u"Sïmple title.\n")
+ self.create_simple_commit("Sïmple title.\n")
# Add some files, stage them: they should show up in the debug output as changed file
filename1 = self.create_file(self.tmp_git_repo)
@@ -103,14 +102,14 @@ class CommitsTests(BaseTestCase):
filename2 = self.create_file(self.tmp_git_repo)
git("add", filename2, _cwd=self.tmp_git_repo)
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: from fïle test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: from fïle test.")
output = gitlint("--msg-filename", tmp_commit_msg_file, "--staged", "--debug",
_cwd=self.tmp_git_repo, _tty_in=False, _err_to_out=True, _ok_code=[3])
# Determine variable parts of expected output
expected_kwargs = self.get_debug_vars_last_commit()
- expected_kwargs.update({'changed_files': sstr(sorted([filename1, filename2]))})
+ expected_kwargs.update({'changed_files': sorted([filename1, filename2])})
# It's not really possible to determine the "Date: ..." line that is part of the debug output as this date
# is not taken from git but instead generated by gitlint itself. As a workaround, we extract the date from the
@@ -128,9 +127,9 @@ class CommitsTests(BaseTestCase):
def test_lint_head(self):
""" Testing whether we can also recognize special refs like 'HEAD' """
tmp_git_repo = self.create_tmp_git_repo()
- self.create_simple_commit(u"Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
- self.create_simple_commit(u"Sïmple title", git_repo=tmp_git_repo)
- self.create_simple_commit(u"WIP: Sïmple title\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
+ self.create_simple_commit("Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
+ self.create_simple_commit("Sïmple title", git_repo=tmp_git_repo)
+ self.create_simple_commit("WIP: Sïmple title\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
output = gitlint("--commits", "HEAD", _cwd=tmp_git_repo, _tty_in=True, _ok_code=[3])
revlist = git("rev-list", "HEAD", _tty_in=True, _cwd=tmp_git_repo).split()
@@ -143,14 +142,14 @@ class CommitsTests(BaseTestCase):
""" Tests multiple commits of which some rules get igonored because of ignore-* rules """
# Create repo and some commits
tmp_git_repo = self.create_tmp_git_repo()
- self.create_simple_commit(u"Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
+ self.create_simple_commit("Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo)
# Normally, this commit will give T3 (trailing-punctuation), T5 (WIP) and B5 (bod-too-short) violations
# But in this case only B5 because T3 and T5 are being ignored because of config
- self.create_simple_commit(u"Release: WIP tïtle.\n\nShort", git_repo=tmp_git_repo)
+ self.create_simple_commit("Release: WIP tïtle.\n\nShort", git_repo=tmp_git_repo)
# In the following 2 commits, the T3 violations are as normal
self.create_simple_commit(
- u"Sïmple WIP title3.\n\nThis is \ta relëase commit\nMore info", git_repo=tmp_git_repo)
- self.create_simple_commit(u"Sïmple title4.\n\nSimple bödy describing the commit4", git_repo=tmp_git_repo)
+ "Sïmple WIP title3.\n\nThis is \ta relëase commit\nMore info", git_repo=tmp_git_repo)
+ self.create_simple_commit("Sïmple title4.\n\nSimple bödy describing the commit4", git_repo=tmp_git_repo)
revlist = git("rev-list", "HEAD", _tty_in=True, _cwd=tmp_git_repo).split()
config_path = self.get_sample_path("config/ignore-release-commits")