summaryrefslogtreecommitdiffstats
path: root/qa
diff options
context:
space:
mode:
Diffstat (limited to 'qa')
-rw-r--r--qa/base.py20
-rw-r--r--qa/requirements.txt6
-rw-r--r--qa/samples/user_rules/extra/extra_rules.py33
-rw-r--r--qa/shell.py20
-rw-r--r--qa/test_commits.py51
-rw-r--r--qa/test_config.py30
-rw-r--r--qa/test_contrib.py10
-rw-r--r--qa/test_gitlint.py63
-rw-r--r--qa/test_hooks.py38
-rw-r--r--qa/test_named_rules.py4
-rw-r--r--qa/test_stdin.py14
-rw-r--r--qa/test_user_defined.py8
-rw-r--r--qa/utils.py49
13 files changed, 143 insertions, 203 deletions
diff --git a/qa/base.py b/qa/base.py
index f9e520a..acb921d 100644
--- a/qa/base.py
+++ b/qa/base.py
@@ -10,18 +10,13 @@ import sys
import tempfile
from datetime import datetime
from uuid import uuid4
+from unittest import TestCase
import arrow
-try:
- # python 2.x
- from unittest2 import TestCase
-except ImportError:
- # python 3.x
- from unittest import TestCase
from qa.shell import git, gitlint, RunningCommand
-from qa.utils import DEFAULT_ENCODING, ustr
+from qa.utils import DEFAULT_ENCODING
class BaseTestCase(TestCase):
@@ -56,13 +51,14 @@ class BaseTestCase(TestCase):
def assertEqualStdout(self, output, expected): # pylint: disable=invalid-name
self.assertIsInstance(output, RunningCommand)
- output = ustr(output.stdout)
+ output = output.stdout.decode(DEFAULT_ENCODING)
output = output.replace('\r', '')
self.assertMultiLineEqual(output, expected)
@classmethod
def generate_temp_path(cls):
- return os.path.realpath("/tmp/gitlint-test-{0}".format(datetime.now().strftime("%Y%m%d-%H%M%S-%f")))
+ timestamp = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
+ return os.path.realpath(f"/tmp/gitlint-test-{timestamp}")
@classmethod
def create_tmp_git_repo(cls):
@@ -89,7 +85,7 @@ class BaseTestCase(TestCase):
@staticmethod
def create_file(parent_dir):
""" Creates a file inside a passed directory. Returns filename."""
- test_filename = u"test-fïle-" + str(uuid4())
+ test_filename = "test-fïle-" + str(uuid4())
io.open(os.path.join(parent_dir, test_filename), 'a', encoding=DEFAULT_ENCODING).close()
return test_filename
@@ -171,8 +167,8 @@ class BaseTestCase(TestCase):
@staticmethod
def get_system_info_dict():
""" Returns a dict with items related to system values logged by `gitlint --debug` """
- expected_gitlint_version = gitlint("--version").replace("gitlint, version ", "").replace("\n", "")
- expected_git_version = git("--version").replace("\n", "")
+ expected_gitlint_version = gitlint("--version").replace("gitlint, version ", "").strip()
+ expected_git_version = git("--version").strip()
return {'platform': platform.platform(), 'python_version': sys.version,
'git_version': expected_git_version, 'gitlint_version': expected_gitlint_version,
'GITLINT_USE_SH_LIB': BaseTestCase.GITLINT_USE_SH_LIB, 'DEFAULT_ENCODING': DEFAULT_ENCODING}
diff --git a/qa/requirements.txt b/qa/requirements.txt
index f042dad..32f4662 100644
--- a/qa/requirements.txt
+++ b/qa/requirements.txt
@@ -1,4 +1,4 @@
-sh==1.12.14
-pytest==4.6.3;
-arrow==0.15.5;
+sh==1.14.1
+pytest==6.1.2;
+arrow==0.17.0;
gitlint # no version as you want to test the currently installed version
diff --git a/qa/samples/user_rules/extra/extra_rules.py b/qa/samples/user_rules/extra/extra_rules.py
index 6fb985f..9a0ae6d 100644
--- a/qa/samples/user_rules/extra/extra_rules.py
+++ b/qa/samples/user_rules/extra/extra_rules.py
@@ -2,18 +2,17 @@
from gitlint.rules import CommitRule, RuleViolation, ConfigurationRule
from gitlint.options import IntOption, StrOption, ListOption
-from gitlint.utils import sstr
class GitContextRule(CommitRule):
""" Rule that tests whether we can correctly access certain gitcontext properties """
- name = u"gïtcontext"
+ name = "gïtcontext"
id = "UC1"
def validate(self, commit):
violations = [
- RuleViolation(self.id, u"GitContext.current_branch: {0}".format(commit.context.current_branch), line_nr=1),
- RuleViolation(self.id, u"GitContext.commentchar: {0}".format(commit.context.commentchar), line_nr=1)
+ RuleViolation(self.id, f"GitContext.current_branch: {commit.context.current_branch}", line_nr=1),
+ RuleViolation(self.id, f"GitContext.commentchar: {commit.context.commentchar}", line_nr=1)
]
return violations
@@ -21,13 +20,13 @@ class GitContextRule(CommitRule):
class GitCommitRule(CommitRule):
""" Rule that tests whether we can correctly access certain commit properties """
- name = u"gïtcommit"
+ name = "gïtcommit"
id = "UC2"
def validate(self, commit):
violations = [
- RuleViolation(self.id, u"GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1),
- RuleViolation(self.id, u"GitCommit.custom_prop: {0}".format(commit.custom_prop), line_nr=1),
+ RuleViolation(self.id, f"GitCommit.branches: {commit.branches}", line_nr=1),
+ RuleViolation(self.id, f"GitCommit.custom_prop: {commit.custom_prop}", line_nr=1),
]
return violations
@@ -35,16 +34,16 @@ class GitCommitRule(CommitRule):
class GitlintConfigurationRule(ConfigurationRule):
""" Rule that tests whether we can correctly access the config as well as modify the commit message """
- name = u"cönfigrule"
+ name = "cönfigrule"
id = "UC3"
def apply(self, config, commit):
# We add a line to the commit message body that pulls a value from config, this proves we can modify the body
# and read the config contents
- commit.message.body.append("{0} ".format(config.target)) # trailing whitespace deliberate to trigger violation
+ commit.message.body.append(f"{config.target} ") # trailing whitespace deliberate to trigger violation
# We set a custom property that we access in CommitRule, to prove we can add extra properties to the commit
- commit.custom_prop = u"foöbar"
+ commit.custom_prop = "foöbar"
# We also ignore some extra rules, proving that we can modify the config
config.ignore.append("B4")
@@ -52,18 +51,18 @@ class GitlintConfigurationRule(ConfigurationRule):
class ConfigurableCommitRule(CommitRule):
""" Rule that tests that we can add configuration to user-defined rules """
- name = u"configürable"
+ name = "configürable"
id = "UC4"
- options_spec = [IntOption(u"int-öption", 2, u"int-öption description"),
- StrOption(u"str-öption", u"föo", u"int-öption description"),
- ListOption(u"list-öption", [u"foo", u"bar"], u"list-öption description")]
+ options_spec = [IntOption("int-öption", 2, "int-öption description"),
+ StrOption("str-öption", "föo", "int-öption description"),
+ ListOption("list-öption", ["foo", "bar"], "list-öption description")]
def validate(self, _):
violations = [
- RuleViolation(self.id, u"int-öption: {0}".format(self.options[u'int-öption'].value), line_nr=1),
- RuleViolation(self.id, u"str-öption: {0}".format(self.options[u'str-öption'].value), line_nr=1),
- RuleViolation(self.id, u"list-öption: {0}".format(sstr(self.options[u'list-öption'].value)), line_nr=1),
+ RuleViolation(self.id, f"int-öption: {self.options[u'int-öption'].value}", line_nr=1),
+ RuleViolation(self.id, f"str-öption: {self.options[u'str-öption'].value}", line_nr=1),
+ RuleViolation(self.id, f"list-öption: {self.options[u'list-öption'].value}", line_nr=1),
]
return violations
diff --git a/qa/shell.py b/qa/shell.py
index 43e5bbd..97dcd2c 100644
--- a/qa/shell.py
+++ b/qa/shell.py
@@ -3,10 +3,11 @@
# on gitlint internals for our integration testing framework.
import subprocess
-from qa.utils import ustr, USE_SH_LIB, IS_PY2
+from qa.utils import USE_SH_LIB, DEFAULT_ENCODING
if USE_SH_LIB:
from sh import git, echo, gitlint # pylint: disable=unused-import,no-name-in-module,import-error
+ gitlint = gitlint.bake(_unify_ttys=True, _tty_in=True) # pylint: disable=invalid-name
# import exceptions separately, this makes it a little easier to mock them out in the unit tests
from sh import CommandNotFound, ErrorReturnCode, RunningCommand # pylint: disable=import-error
@@ -16,7 +17,7 @@ else:
""" Exception indicating a command was not found during execution """
pass
- class RunningCommand(object):
+ class RunningCommand:
pass
class ShResult(RunningCommand):
@@ -27,7 +28,7 @@ else:
self.full_cmd = full_cmd
# TODO(jorisroovers): The 'sh' library by default will merge stdout and stderr. We mimic this behavior
# for now until we fully remove the 'sh' library.
- self.stdout = stdout + ustr(stderr)
+ self.stdout = stdout + stderr.decode(DEFAULT_ENCODING)
self.stderr = stderr
self.exit_code = exitcode
@@ -55,14 +56,9 @@ else:
# a non-zero exit code -> just return the entire result
if hasattr(result, 'exit_code') and result.exit_code > 0:
return result
- return ustr(result)
+ return str(result)
def _exec(*args, **kwargs):
- if IS_PY2:
- no_command_error = OSError # noqa pylint: disable=undefined-variable,invalid-name
- else:
- no_command_error = FileNotFoundError # noqa pylint: disable=undefined-variable
-
pipe = subprocess.PIPE
popen_kwargs = {'stdout': pipe, 'stderr': pipe, 'shell': kwargs.get('_tty_out', False)}
if '_cwd' in kwargs:
@@ -73,11 +69,11 @@ else:
try:
p = subprocess.Popen(args, **popen_kwargs)
result = p.communicate()
- except no_command_error:
- raise CommandNotFound
+ except FileNotFoundError as exc:
+ raise CommandNotFound from exc
exit_code = p.returncode
- stdout = ustr(result[0])
+ stdout = result[0].decode(DEFAULT_ENCODING)
stderr = result[1] # 'sh' does not decode the stderr bytes to unicode
full_cmd = '' if args is None else ' '.join(args)
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")
diff --git a/qa/test_config.py b/qa/test_config.py
index 9415990..9c00b95 100644
--- a/qa/test_config.py
+++ b/qa/test_config.py
@@ -5,30 +5,30 @@ import re
from qa.shell import gitlint
from qa.base import BaseTestCase
-from qa.utils import sstr, ustr
+from qa.utils import DEFAULT_ENCODING
class ConfigTests(BaseTestCase):
""" Integration tests for gitlint configuration and configuration precedence. """
def test_ignore_by_id(self):
- self.create_simple_commit(u"WIP: Thïs is a title.\nContënt on the second line")
+ self.create_simple_commit("WIP: Thïs is a title.\nContënt on the second line")
output = gitlint("--ignore", "T5,B4", _tty_in=True, _cwd=self.tmp_git_repo, _ok_code=[1])
- expected = u"1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
+ expected = "1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
self.assertEqualStdout(output, expected)
def test_ignore_by_name(self):
- self.create_simple_commit(u"WIP: Thïs is a title.\nContënt on the second line")
+ self.create_simple_commit("WIP: Thïs is a title.\nContënt on the second line")
output = gitlint("--ignore", "title-must-not-contain-word,body-first-line-empty",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
- expected = u"1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
+ expected = "1: T3 Title has trailing punctuation (.): \"WIP: Thïs is a title.\"\n"
self.assertEqualStdout(output, expected)
def test_verbosity(self):
- self.create_simple_commit(u"WIP: Thïs is a title.\nContënt on the second line")
+ self.create_simple_commit("WIP: Thïs is a title.\nContënt on the second line")
output = gitlint("-v", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
- expected = u"1: T3\n1: T5\n2: B4\n"
+ expected = "1: T3\n1: T5\n2: B4\n"
self.assertEqualStdout(output, expected)
output = gitlint("-vv", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
@@ -42,12 +42,12 @@ class ConfigTests(BaseTestCase):
self.assertEqualStdout(output, "")
def test_set_rule_option(self):
- self.create_simple_commit(u"This ïs a title.")
+ self.create_simple_commit("This ïs a title.")
output = gitlint("-c", "title-max-length.line-length=5", _tty_in=True, _cwd=self.tmp_git_repo, _ok_code=[3])
self.assertEqualStdout(output, self.get_expected("test_config/test_set_rule_option_1"))
def test_config_from_file(self):
- commit_msg = u"WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
+ commit_msg = "WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
"This line of the body is here because we need it"
self.create_simple_commit(commit_msg)
config_path = self.get_sample_path("config/gitlintconfig")
@@ -58,14 +58,14 @@ class ConfigTests(BaseTestCase):
# Test both on existing and new repo (we've had a bug in the past that was unique to empty repos)
repos = [self.tmp_git_repo, self.create_tmp_git_repo()]
for target_repo in repos:
- commit_msg = u"WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
+ commit_msg = "WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
"This line of the body is here because we need it"
filename = self.create_simple_commit(commit_msg, git_repo=target_repo)
config_path = self.get_sample_path("config/gitlintconfig")
output = gitlint("--config", config_path, "--debug", _cwd=target_repo, _tty_in=True, _ok_code=[5])
expected_kwargs = self.get_debug_vars_last_commit(git_repo=target_repo)
- expected_kwargs.update({'config_path': config_path, 'changed_files': sstr([filename])})
+ expected_kwargs.update({'config_path': config_path, 'changed_files': [filename]})
self.assertEqualStdout(output, self.get_expected("test_config/test_config_from_file_debug_1",
expected_kwargs))
@@ -75,7 +75,7 @@ class ConfigTests(BaseTestCase):
# We invoke gitlint, configuring it via env variables, we can check whether gitlint picks these up correctly
# by comparing the debug output with what we'd expect
target_repo = self.create_tmp_git_repo()
- commit_msg = u"WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
+ commit_msg = "WIP: Thïs is a title thåt is a bit longer.\nContent on the second line\n" + \
"This line of the body is here because we need it"
filename = self.create_simple_commit(commit_msg, git_repo=target_repo)
env = self.create_environment({"GITLINT_DEBUG": "1", "GITLINT_VERBOSITY": "2",
@@ -84,12 +84,12 @@ class ConfigTests(BaseTestCase):
"GITLINT_COMMITS": self.get_last_commit_hash(git_repo=target_repo)})
output = gitlint(_env=env, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
expected_kwargs = self.get_debug_vars_last_commit(git_repo=target_repo)
- expected_kwargs.update({'changed_files': sstr([filename])})
+ expected_kwargs.update({'changed_files': [filename]})
self.assertEqualStdout(output, self.get_expected("test_config/test_config_from_env_1", expected_kwargs))
# For some env variables, we need a separate test ast they are mutually exclusive with the ones tested above
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: msg-fïlename test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: msg-fïlename test.")
env = self.create_environment({"GITLINT_DEBUG": "1", "GITLINT_TARGET": target_repo,
"GITLINT_SILENT": "1", "GITLINT_STAGED": "1"})
@@ -99,7 +99,7 @@ class ConfigTests(BaseTestCase):
# Extract date from actual output to insert it into the expected output
# We have to do this since there's no way for us to deterministically know that date otherwise
p = re.compile("Date: (.*)\n", re.UNICODE | re.MULTILINE)
- result = p.search(ustr(output.stdout))
+ result = p.search(output.stdout.decode(DEFAULT_ENCODING))
date = result.group(1).strip()
expected_kwargs.update({"date": date})
diff --git a/qa/test_contrib.py b/qa/test_contrib.py
index e2b4bc5..e599d50 100644
--- a/qa/test_contrib.py
+++ b/qa/test_contrib.py
@@ -8,19 +8,19 @@ class ContribRuleTests(BaseTestCase):
""" Integration tests for contrib rules."""
def test_contrib_rules(self):
- self.create_simple_commit(u"WIP Thi$ is å title\n\nMy bödy that is a bit longer than 20 chars")
+ self.create_simple_commit("WIP Thi$ is å title\n\nMy bödy that is a bit longer than 20 chars")
output = gitlint("--contrib", "contrib-title-conventional-commits,CC1",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4])
self.assertEqualStdout(output, self.get_expected("test_contrib/test_contrib_rules_1"))
def test_contrib_rules_with_config(self):
- self.create_simple_commit(u"WIP Thi$ is å title\n\nMy bödy that is a bit longer than 20 chars")
+ self.create_simple_commit("WIP Thi$ is å title\n\nMy bödy that is a bit longer than 20 chars")
output = gitlint("--contrib", "contrib-title-conventional-commits,CC1",
- "-c", u"contrib-title-conventional-commits.types=föo,bår",
+ "-c", "contrib-title-conventional-commits.types=föo,bår",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4])
self.assertEqualStdout(output, self.get_expected("test_contrib/test_contrib_rules_with_config_1"))
def test_invalid_contrib_rules(self):
self.create_simple_commit("WIP: test")
- output = gitlint("--contrib", u"föobar,CC1", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[255])
- self.assertEqualStdout(output, u"Config Error: No contrib rule with id or name 'föobar' found.\n")
+ output = gitlint("--contrib", "föobar,CC1", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[255])
+ self.assertEqualStdout(output, "Config Error: No contrib rule with id or name 'föobar' found.\n")
diff --git a/qa/test_gitlint.py b/qa/test_gitlint.py
index 2e837b9..0200d76 100644
--- a/qa/test_gitlint.py
+++ b/qa/test_gitlint.py
@@ -12,7 +12,7 @@ class IntegrationTests(BaseTestCase):
def test_successful(self):
# Test for STDIN with and without a TTY attached
- 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")
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True, _err_to_out=True)
self.assertEqualStdout(output, "")
@@ -22,26 +22,26 @@ class IntegrationTests(BaseTestCase):
# Different commentchar (Note: tried setting this to a special unicode char, but git doesn't like that)
git("config", "--add", "core.commentchar", "$", _cwd=self.tmp_git_repo)
- self.create_simple_commit(u"Sïmple title\n\nSimple bödy describing the commit\n$after commentchar\t ignored")
+ self.create_simple_commit("Sïmple title\n\nSimple bödy describing the commit\n$after commentchar\t ignored")
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True, _err_to_out=True)
self.assertEqualStdout(output, "")
def test_successful_merge_commit(self):
# Create branch on master
- self.create_simple_commit(u"Cömmit on master\n\nSimple bödy")
+ self.create_simple_commit("Cömmit on master\n\nSimple bödy")
# Create test branch, add a commit and determine the commit hash
git("checkout", "-b", "test-branch", _cwd=self.tmp_git_repo)
git("checkout", "test-branch", _cwd=self.tmp_git_repo)
- commit_title = u"Commit on test-brånch with a pretty long title that will cause issues when merging"
- self.create_simple_commit(u"{0}\n\nSïmple body".format(commit_title))
+ commit_title = "Commit on test-brånch with a pretty long title that will cause issues when merging"
+ self.create_simple_commit(f"{commit_title}\n\nSïmple body")
hash = self.get_last_commit_hash()
# Checkout master and merge the commit
# We explicitly set the title of the merge commit to the title of the previous commit as this or similar
# behavior is what many tools do that handle merges (like github, gerrit, etc).
git("checkout", "master", _cwd=self.tmp_git_repo)
- git("merge", "--no-ff", "-m", u"Merge '{0}'".format(commit_title), hash, _cwd=self.tmp_git_repo)
+ git("merge", "--no-ff", "-m", f"Merge '{commit_title}'", hash, _cwd=self.tmp_git_repo)
# Run gitlint and assert output is empty
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True)
@@ -50,14 +50,13 @@ class IntegrationTests(BaseTestCase):
# Assert that we do see the error if we disable the ignore-merge-commits option
output = gitlint("-c", "general.ignore-merge-commits=false", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
self.assertEqual(output.exit_code, 1)
- self.assertEqualStdout(output,
- u"1: T1 Title exceeds max length (90>72): \"Merge '{0}'\"\n".format(commit_title))
+ self.assertEqualStdout(output, f"1: T1 Title exceeds max length (90>72): \"Merge '{commit_title}'\"\n")
def test_fixup_commit(self):
# Create a normal commit and assert that it has a violation
- test_filename = self.create_simple_commit(u"Cömmit on WIP master\n\nSimple bödy that is long enough")
+ test_filename = self.create_simple_commit("Cömmit on WIP master\n\nSimple bödy that is long enough")
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
- expected = u"1: T5 Title contains the word 'WIP' (case-insensitive): \"Cömmit on WIP master\"\n"
+ expected = "1: T5 Title contains the word 'WIP' (case-insensitive): \"Cömmit on WIP master\"\n"
self.assertEqualStdout(output, expected)
# Make a small modification to the commit and commit it using fixup commit
@@ -66,7 +65,7 @@ class IntegrationTests(BaseTestCase):
# https://stackoverflow.com/questions/22392377/
# error-writing-a-file-with-file-write-in-python-unicodeencodeerror
# So just keeping it simple - ASCII will here
- fh.write(u"Appending some stuff\n")
+ fh.write("Appending some stuff\n")
git("add", test_filename, _cwd=self.tmp_git_repo)
@@ -79,13 +78,13 @@ class IntegrationTests(BaseTestCase):
# Make sure that if we set the ignore-fixup-commits option to false that we do still see the violations
output = gitlint("-c", "general.ignore-fixup-commits=false", _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
- expected = u"1: T5 Title contains the word 'WIP' (case-insensitive): \"fixup! Cömmit on WIP master\"\n" + \
- u"3: B6 Body message is missing\n"
+ expected = "1: T5 Title contains the word 'WIP' (case-insensitive): \"fixup! Cömmit on WIP master\"\n" + \
+ "3: B6 Body message is missing\n"
self.assertEqualStdout(output, expected)
def test_revert_commit(self):
- self.create_simple_commit(u"WIP: Cömmit on master.\n\nSimple bödy")
+ self.create_simple_commit("WIP: Cömmit on master.\n\nSimple bödy")
hash = self.get_last_commit_hash()
git("revert", hash, _cwd=self.tmp_git_repo)
@@ -97,14 +96,14 @@ class IntegrationTests(BaseTestCase):
output = gitlint("-c", "general.ignore-revert-commits=false",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
self.assertEqual(output.exit_code, 1)
- expected = u"1: T5 Title contains the word 'WIP' (case-insensitive): \"Revert \"WIP: Cömmit on master.\"\"\n"
+ expected = "1: T5 Title contains the word 'WIP' (case-insensitive): \"Revert \"WIP: Cömmit on master.\"\"\n"
self.assertEqualStdout(output, expected)
def test_squash_commit(self):
# Create a normal commit and assert that it has a violation
- test_filename = self.create_simple_commit(u"Cömmit on WIP master\n\nSimple bödy that is long enough")
+ test_filename = self.create_simple_commit("Cömmit on WIP master\n\nSimple bödy that is long enough")
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[1])
- expected = u"1: T5 Title contains the word 'WIP' (case-insensitive): \"Cömmit on WIP master\"\n"
+ expected = "1: T5 Title contains the word 'WIP' (case-insensitive): \"Cömmit on WIP master\"\n"
self.assertEqualStdout(output, expected)
# Make a small modification to the commit and commit it using squash commit
@@ -113,11 +112,11 @@ class IntegrationTests(BaseTestCase):
# https://stackoverflow.com/questions/22392377/
# error-writing-a-file-with-file-write-in-python-unicodeencodeerror
# So just keeping it simple - ASCII will here
- fh.write(u"Appending some stuff\n")
+ fh.write("Appending some stuff\n")
git("add", test_filename, _cwd=self.tmp_git_repo)
- git("commit", "--squash", self.get_last_commit_hash(), "-m", u"Töo short body", _cwd=self.tmp_git_repo)
+ git("commit", "--squash", self.get_last_commit_hash(), "-m", "Töo short body", _cwd=self.tmp_git_repo)
# Assert that gitlint does not show an error for the fixup commit
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True)
@@ -127,25 +126,25 @@ class IntegrationTests(BaseTestCase):
# Make sure that if we set the ignore-squash-commits option to false that we do still see the violations
output = gitlint("-c", "general.ignore-squash-commits=false",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2])
- expected = u"1: T5 Title contains the word 'WIP' (case-insensitive): \"squash! Cömmit on WIP master\"\n" + \
- u"3: B5 Body message is too short (14<20): \"Töo short body\"\n"
+ expected = "1: T5 Title contains the word 'WIP' (case-insensitive): \"squash! Cömmit on WIP master\"\n" + \
+ "3: B5 Body message is too short (14<20): \"Töo short body\"\n"
self.assertEqualStdout(output, expected)
def test_violations(self):
- commit_msg = u"WIP: This ïs a title.\nContent on the sëcond line"
+ commit_msg = "WIP: This ïs a title.\nContent on the sëcond line"
self.create_simple_commit(commit_msg)
output = gitlint(_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[3])
self.assertEqualStdout(output, self.get_expected("test_gitlint/test_violations_1"))
def test_msg_filename(self):
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: msg-fïlename test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: msg-fïlename test.")
output = gitlint("--msg-filename", tmp_commit_msg_file, _tty_in=True, _ok_code=[3])
self.assertEqualStdout(output, self.get_expected("test_gitlint/test_msg_filename_1"))
def test_msg_filename_no_tty(self):
""" Make sure --msg-filename option also works with no TTY attached """
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: msg-fïlename NO TTY test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: msg-fïlename NO TTY test.")
# We need to set _err_to_out explicitly for sh to merge stdout and stderr output in case there's
# no TTY attached to STDIN
@@ -159,24 +158,24 @@ class IntegrationTests(BaseTestCase):
def test_no_git_name_set(self):
""" Ensure we print out a helpful message if user.name is not set """
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: msg-fïlename NO name test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: msg-fïlename NO name test.")
# Name is checked before email so this isn't strictly
# necessary but seems good for consistency.
- env = self.create_tmp_git_config(u"[user]\n email = test-emåil@foo.com\n")
+ env = self.create_tmp_git_config("[user]\n email = test-emåil@foo.com\n")
output = gitlint("--staged", "--msg-filename", tmp_commit_msg_file,
_ok_code=[self.GIT_CONTEXT_ERROR_CODE],
_env=env)
- expected = u"Missing git configuration: please set user.name\n"
+ expected = "Missing git configuration: please set user.name\n"
self.assertEqualStdout(output, expected)
def test_no_git_email_set(self):
""" Ensure we print out a helpful message if user.email is not set """
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: msg-fïlename NO email test.")
- env = self.create_tmp_git_config(u"[user]\n name = test åuthor\n")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: msg-fïlename NO email test.")
+ env = self.create_tmp_git_config("[user]\n name = test åuthor\n")
output = gitlint("--staged", "--msg-filename", tmp_commit_msg_file,
_ok_code=[self.GIT_CONTEXT_ERROR_CODE],
_env=env)
- expected = u"Missing git configuration: please set user.email\n"
+ expected = "Missing git configuration: please set user.email\n"
self.assertEqualStdout(output, expected)
def test_git_errors(self):
@@ -184,10 +183,10 @@ class IntegrationTests(BaseTestCase):
empty_git_repo = self.create_tmp_git_repo()
output = gitlint(_cwd=empty_git_repo, _tty_in=True, _ok_code=[self.GIT_CONTEXT_ERROR_CODE])
- expected = u"Current branch has no commits. Gitlint requires at least one commit to function.\n"
+ expected = "Current branch has no commits. Gitlint requires at least one commit to function.\n"
self.assertEqualStdout(output, expected)
# Repo has no commits: caused by `git rev-parse`
- output = gitlint(echo(u"WIP: Pïpe test."), "--staged", _cwd=empty_git_repo, _tty_in=False,
+ output = gitlint(echo("WIP: Pïpe test."), "--staged", _cwd=empty_git_repo, _tty_in=False,
_err_to_out=True, _ok_code=[self.GIT_CONTEXT_ERROR_CODE])
self.assertEqualStdout(output, expected)
diff --git a/qa/test_hooks.py b/qa/test_hooks.py
index 7c07a61..80ccbf6 100644
--- a/qa/test_hooks.py
+++ b/qa/test_hooks.py
@@ -24,18 +24,18 @@ class HookTests(BaseTestCase):
# The '--staged' flag used in the commit-msg hook fetches additional information from the underlying
# git repo which means there already needs to be a commit in the repo
# (as gitlint --staged doesn't work against empty repos)
- self.create_simple_commit(u"Commït Title\n\nCommit Body explaining commit.")
+ self.create_simple_commit("Commït Title\n\nCommit Body explaining commit.")
# install git commit-msg hook and assert output
output_installed = gitlint("install-hook", _cwd=self.tmp_git_repo)
- expected_installed = u"Successfully installed gitlint commit-msg hook in %s/.git/hooks/commit-msg\n" % \
+ expected_installed = "Successfully installed gitlint commit-msg hook in %s/.git/hooks/commit-msg\n" % \
self.tmp_git_repo
self.assertEqualStdout(output_installed, expected_installed)
def tearDown(self):
# uninstall git commit-msg hook and assert output
output_uninstalled = gitlint("uninstall-hook", _cwd=self.tmp_git_repo)
- expected_uninstalled = u"Successfully uninstalled gitlint commit-msg hook from %s/.git/hooks/commit-msg\n" % \
+ expected_uninstalled = "Successfully uninstalled gitlint commit-msg hook from %s/.git/hooks/commit-msg\n" % \
self.tmp_git_repo
self.assertEqualStdout(output_uninstalled, expected_uninstalled)
@@ -50,24 +50,24 @@ class HookTests(BaseTestCase):
# Answer 'yes' to question to keep violating commit-msg
if "Your commit message contains the above violations" in line:
response = self.responses[self.response_index]
- stdin.put("{0}\n".format(response))
+ stdin.put(f"{response}\n")
self.response_index = (self.response_index + 1) % len(self.responses)
def test_commit_hook_no_violations(self):
- test_filename = self.create_simple_commit(u"This ïs a title\n\nBody contënt that should work",
+ test_filename = self.create_simple_commit("This ïs a title\n\nBody contënt that should work",
out=self._interact, tty_in=True)
short_hash = self.get_last_commit_short_hash()
expected_output = ["gitlint: checking commit message...\n",
"gitlint: \x1b[32mOK\x1b[0m (no violations in commit message)\n",
- u"[master %s] This ïs a title\n" % short_hash,
+ "[master %s] This ïs a title\n" % short_hash,
" 1 file changed, 0 insertions(+), 0 deletions(-)\n",
- u" create mode 100644 %s\n" % test_filename]
+ " create mode 100644 %s\n" % test_filename]
self.assertListEqual(expected_output, self.githook_output)
def test_commit_hook_continue(self):
self.responses = ["y"]
- test_filename = self.create_simple_commit(u"WIP: This ïs a title.\nContënt on the second line",
+ test_filename = self.create_simple_commit("WIP: This ïs a title.\nContënt on the second line",
out=self._interact, tty_in=True)
# Determine short commit-msg hash, needed to determine expected output
@@ -76,10 +76,10 @@ class HookTests(BaseTestCase):
expected_output = self._violations()
expected_output += ["Continue with commit anyways (this keeps the current commit message)? " +
"[y(es)/n(no)/e(dit)] " +
- u"[master %s] WIP: This ïs a title. Contënt on the second line\n"
+ "[master %s] WIP: This ïs a title. Contënt on the second line\n"
% short_hash,
" 1 file changed, 0 insertions(+), 0 deletions(-)\n",
- u" create mode 100644 %s\n" % test_filename]
+ " create mode 100644 %s\n" % test_filename]
assert len(self.githook_output) == len(expected_output)
for output, expected in zip(self.githook_output, expected_output):
@@ -89,7 +89,7 @@ class HookTests(BaseTestCase):
def test_commit_hook_abort(self):
self.responses = ["n"]
- test_filename = self.create_simple_commit(u"WIP: This ïs a title.\nContënt on the second line",
+ test_filename = self.create_simple_commit("WIP: This ïs a title.\nContënt on the second line",
out=self._interact, ok_code=1, tty_in=True)
git("rm", "-f", test_filename, _cwd=self.tmp_git_repo)
@@ -101,8 +101,8 @@ class HookTests(BaseTestCase):
"Commit aborted.\n",
"Your commit message: \n",
"-----------------------------------------------\n",
- u"WIP: This ïs a title.\n",
- u"Contënt on the second line\n",
+ "WIP: This ïs a title.\n",
+ "Contënt on the second line\n",
"-----------------------------------------------\n"]
self.assertListEqual(expected_output, self.githook_output)
@@ -110,7 +110,7 @@ class HookTests(BaseTestCase):
def test_commit_hook_edit(self):
self.responses = ["e", "y"]
env = {"EDITOR": ":"}
- test_filename = self.create_simple_commit(u"WIP: This ïs a title.\nContënt on the second line",
+ test_filename = self.create_simple_commit("WIP: This ïs a title.\nContënt on the second line",
out=self._interact, env=env, tty_in=True)
git("rm", "-f", test_filename, _cwd=self.tmp_git_repo)
@@ -124,9 +124,9 @@ class HookTests(BaseTestCase):
expected_output += self._violations()[1:]
expected_output += ['Continue with commit anyways (this keeps the current commit message)? ' +
"[y(es)/n(no)/e(dit)] " +
- u"[master %s] WIP: This ïs a title. Contënt on the second line\n" % short_hash,
+ "[master %s] WIP: This ïs a title. Contënt on the second line\n" % short_hash,
" 1 file changed, 0 insertions(+), 0 deletions(-)\n",
- u" create mode 100644 %s\n" % test_filename]
+ " create mode 100644 %s\n" % test_filename]
assert len(self.githook_output) == len(expected_output)
for output, expected in zip(self.githook_output, expected_output):
@@ -147,7 +147,7 @@ class HookTests(BaseTestCase):
```
"""
tmp_git_repo = self.create_tmp_git_repo()
- self.create_simple_commit(u"Simple title\n\nContënt in the body", git_repo=tmp_git_repo)
+ self.create_simple_commit("Simple title\n\nContënt in the body", git_repo=tmp_git_repo)
worktree_dir = self.generate_temp_path()
self.tmp_git_repos.append(worktree_dir) # make sure we clean up the worktree afterwards
@@ -156,10 +156,10 @@ class HookTests(BaseTestCase):
output_installed = gitlint("install-hook", _cwd=worktree_dir)
expected_hook_path = os.path.join(tmp_git_repo, ".git", "hooks", "commit-msg")
- expected_msg = "Successfully installed gitlint commit-msg hook in {0}\n".format(expected_hook_path)
+ expected_msg = f"Successfully installed gitlint commit-msg hook in {expected_hook_path}\r\n"
self.assertEqual(output_installed, expected_msg)
output_uninstalled = gitlint("uninstall-hook", _cwd=worktree_dir)
expected_hook_path = os.path.join(tmp_git_repo, ".git", "hooks", "commit-msg")
- expected_msg = "Successfully uninstalled gitlint commit-msg hook from {0}\n".format(expected_hook_path)
+ expected_msg = f"Successfully uninstalled gitlint commit-msg hook from {expected_hook_path}\r\n"
self.assertEqual(output_uninstalled, expected_msg)
diff --git a/qa/test_named_rules.py b/qa/test_named_rules.py
index 6020bbf..92e968b 100644
--- a/qa/test_named_rules.py
+++ b/qa/test_named_rules.py
@@ -7,14 +7,14 @@ class NamedRuleTests(BaseTestCase):
""" Integration tests for named rules."""
def test_named_rule(self):
- commit_msg = u"WIP: thåt dûr bår\n\nSïmple commit body"
+ commit_msg = "WIP: thåt dûr bår\n\nSïmple commit body"
self.create_simple_commit(commit_msg)
config_path = self.get_sample_path("config/named-rules")
output = gitlint("--config", config_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
self.assertEqualStdout(output, self.get_expected("test_named_rules/test_named_rule_1"))
def test_named_user_rule(self):
- commit_msg = u"Normal cömmit title\n\nSïmple commit message body"
+ commit_msg = "Normal cömmit title\n\nSïmple commit message body"
self.create_simple_commit(commit_msg)
config_path = self.get_sample_path("config/named-user-rules")
extra_path = self.get_sample_path("user_rules/extra")
diff --git a/qa/test_stdin.py b/qa/test_stdin.py
index fff636f..18d6e7e 100644
--- a/qa/test_stdin.py
+++ b/qa/test_stdin.py
@@ -4,7 +4,7 @@ import io
import subprocess
from qa.shell import echo, gitlint
from qa.base import BaseTestCase
-from qa.utils import ustr, DEFAULT_ENCODING
+from qa.utils import DEFAULT_ENCODING
class StdInTests(BaseTestCase):
@@ -18,7 +18,7 @@ class StdInTests(BaseTestCase):
# NOTE: There is no use in testing this with _tty_in=True, because if you pipe something into a command
# there never is a TTY connected to stdin (per definition). We're setting _tty_in=False here to be explicit
# but note that this is always true when piping something into a command.
- output = gitlint(echo(u"WIP: Pïpe test."),
+ output = gitlint(echo("WIP: Pïpe test."),
_cwd=self.tmp_git_repo, _tty_in=False, _err_to_out=True, _ok_code=[3])
self.assertEqualStdout(output, self.get_expected("test_stdin/test_stdin_pipe_1"))
@@ -28,7 +28,7 @@ class StdInTests(BaseTestCase):
This is the equivalent of doing:
$ echo -n "" | gitlint
"""
- commit_msg = u"WIP: This ïs a title.\nContent on the sëcond line"
+ commit_msg = "WIP: This ïs a title.\nContent on the sëcond line"
self.create_simple_commit(commit_msg)
# We need to set _err_to_out explicitly for sh to merge stdout and stderr output in case there's
@@ -36,21 +36,21 @@ class StdInTests(BaseTestCase):
# http://amoffat.github.io/sh/sections/special_arguments.html?highlight=_tty_in#err-to-out
output = gitlint(echo("-n", ""), _cwd=self.tmp_git_repo, _tty_in=False, _err_to_out=True, _ok_code=[3])
- self.assertEqual(ustr(output), self.get_expected("test_stdin/test_stdin_pipe_empty_1"))
+ self.assertEqual(output, self.get_expected("test_stdin/test_stdin_pipe_empty_1"))
def test_stdin_file(self):
""" Test the scenario where STDIN is a regular file (stat.S_ISREG = True)
This is the equivalent of doing:
$ gitlint < myfile
"""
- tmp_commit_msg_file = self.create_tmpfile(u"WIP: STDIN ïs a file test.")
+ tmp_commit_msg_file = self.create_tmpfile("WIP: STDIN ïs a file test.")
with io.open(tmp_commit_msg_file, encoding=DEFAULT_ENCODING) as file_handle:
# We need to use subprocess.Popen() here instead of sh because when passing a file_handle to sh, it will
# deal with reading the file itself instead of passing it on to gitlint as a STDIN. Since we're trying to
# test for the condition where stat.S_ISREG == True that won't work for us here.
- p = subprocess.Popen(u"gitlint", stdin=file_handle, cwd=self.tmp_git_repo,
+ p = subprocess.Popen("gitlint", stdin=file_handle, cwd=self.tmp_git_repo,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, _ = p.communicate()
- self.assertEqual(ustr(output), self.get_expected("test_stdin/test_stdin_file_1"))
+ self.assertEqual(output.decode(DEFAULT_ENCODING), self.get_expected("test_stdin/test_stdin_file_1"))
diff --git a/qa/test_user_defined.py b/qa/test_user_defined.py
index 566d0b2..378ab36 100644
--- a/qa/test_user_defined.py
+++ b/qa/test_user_defined.py
@@ -10,7 +10,7 @@ class UserDefinedRuleTests(BaseTestCase):
def test_user_defined_rules_examples1(self):
""" Test the user defined rules in the top-level `examples/` directory """
extra_path = self.get_example_path()
- commit_msg = u"WIP: Thi$ is å title\nContent on the second line"
+ commit_msg = "WIP: Thi$ is å title\nContent on the second line"
self.create_simple_commit(commit_msg)
output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5])
self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_1"))
@@ -18,7 +18,7 @@ class UserDefinedRuleTests(BaseTestCase):
def test_user_defined_rules_examples2(self):
""" Test the user defined rules in the top-level `examples/` directory """
extra_path = self.get_example_path()
- commit_msg = u"Release: Thi$ is å title\nContent on the second line\n$This line is ignored \nThis isn't\t\n"
+ commit_msg = "Release: Thi$ is å title\nContent on the second line\n$This line is ignored \nThis isn't\t\n"
self.create_simple_commit(commit_msg)
output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4])
self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_2"))
@@ -26,7 +26,7 @@ class UserDefinedRuleTests(BaseTestCase):
def test_user_defined_rules_examples_with_config(self):
""" Test the user defined rules in the top-level `examples/` directory """
extra_path = self.get_example_path()
- commit_msg = u"WIP: Thi$ is å title\nContent on the second line"
+ commit_msg = "WIP: Thi$ is å title\nContent on the second line"
self.create_simple_commit(commit_msg)
output = gitlint("--extra-path", extra_path, "-c", "body-max-line-count.max-line-count=1",
_cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[6])
@@ -35,7 +35,7 @@ class UserDefinedRuleTests(BaseTestCase):
def test_user_defined_rules_extra(self):
extra_path = self.get_sample_path("user_rules/extra")
- commit_msg = u"WIP: Thi$ is å title\nContent on the second line"
+ commit_msg = "WIP: Thi$ is å title\nContent on the second line"
self.create_simple_commit(commit_msg)
output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[9])
self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_extra_1",
diff --git a/qa/utils.py b/qa/utils.py
index f44917e..c75872b 100644
--- a/qa/utils.py
+++ b/qa/utils.py
@@ -1,6 +1,5 @@
# pylint: disable=bad-option-value,unidiomatic-typecheck,undefined-variable,no-else-return
import platform
-import sys
import os
import locale
@@ -16,16 +15,6 @@ def platform_is_windows():
PLATFORM_IS_WINDOWS = platform_is_windows()
########################################################################################################################
-# IS_PY2
-
-
-def is_py2():
- return sys.version_info[0] == 2
-
-
-IS_PY2 = is_py2()
-
-########################################################################################################################
# USE_SH_LIB
# Determine whether to use the `sh` library
# On windows we won't want to use the sh library since it's not supported - instead we'll use our own shell module.
@@ -71,41 +60,3 @@ def getpreferredencoding():
DEFAULT_ENCODING = getpreferredencoding()
-
-########################################################################################################################
-# Unicode utility functions
-
-
-def ustr(obj):
- """ Python 2 and 3 utility method that converts an obj to unicode in python 2 and to a str object in python 3"""
- if IS_PY2:
- # If we are getting a string, then do an explicit decode
- # else, just call the unicode method of the object
- if type(obj) in [str, basestring]: # pragma: no cover # noqa
- return unicode(obj, DEFAULT_ENCODING) # pragma: no cover # noqa
- else:
- return unicode(obj) # pragma: no cover # noqa
- else:
- if type(obj) in [bytes]:
- return obj.decode(DEFAULT_ENCODING)
- else:
- return str(obj)
-
-
-def sstr(obj):
- """ Python 2 and 3 utility method that converts an obj to a DEFAULT_ENCODING encoded string in python 2
- and to unicode in python 3.
- Especially useful for implementing __str__ methods in python 2: http://stackoverflow.com/a/1307210/381010"""
- if IS_PY2:
- # For lists and tuples in python2, remove unicode string representation characters.
- # i.e. ensure lists are printed as ['a', 'b'] and not [u'a', u'b']
- if type(obj) in [list]:
- return [sstr(item) for item in obj] # pragma: no cover # noqa
- elif type(obj) in [tuple]:
- return tuple(sstr(item) for item in obj) # pragma: no cover # noqa
-
- return unicode(obj).encode(DEFAULT_ENCODING) # pragma: no cover # noqa
- else:
- return obj # pragma: no cover
-
-########################################################################################################################