summaryrefslogtreecommitdiffstats
path: root/gitlint/tests/config
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-01-25 13:26:35 +0000
commit4fee3e091a8d79a40f70ff9c1f87b29b9340049a (patch)
tree465ad9629a8ee56548bd6c51c3fc710907564911 /gitlint/tests/config
parentReleasing debian version 0.14.0-1. (diff)
downloadgitlint-4fee3e091a8d79a40f70ff9c1f87b29b9340049a.tar.xz
gitlint-4fee3e091a8d79a40f70ff9c1f87b29b9340049a.zip
Merging upstream version 0.15.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint/tests/config')
-rw-r--r--gitlint/tests/config/test_config.py69
-rw-r--r--gitlint/tests/config/test_config_builder.py80
-rw-r--r--gitlint/tests/config/test_config_precedence.py30
-rw-r--r--gitlint/tests/config/test_rule_collection.py22
4 files changed, 93 insertions, 108 deletions
diff --git a/gitlint/tests/config/test_config.py b/gitlint/tests/config/test_config.py
index b981a86..93e35de 100644
--- a/gitlint/tests/config/test_config.py
+++ b/gitlint/tests/config/test_config.py
@@ -1,16 +1,11 @@
# -*- coding: utf-8 -*-
-try:
- # python 2.x
- from mock import patch
-except ImportError:
- # python 3.x
- from unittest.mock import patch # pylint: disable=no-name-in-module, import-error
+from unittest.mock import patch
from gitlint import rules
from gitlint.config import LintConfig, LintConfigError, LintConfigGenerator, GITLINT_CONFIG_TEMPLATE_SRC_PATH
from gitlint import options
-from gitlint.tests.base import BaseTestCase, ustr
+from gitlint.tests.base import BaseTestCase
class LintConfigTests(BaseTestCase):
@@ -29,20 +24,20 @@ class LintConfigTests(BaseTestCase):
config = LintConfig()
# non-existing rule
- expected_error_msg = u"No such rule 'föobar'"
+ expected_error_msg = "No such rule 'föobar'"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config.set_rule_option(u'föobar', u'lïne-length', 60)
# non-existing option
- expected_error_msg = u"Rule 'title-max-length' has no option 'föobar'"
+ expected_error_msg = "Rule 'title-max-length' has no option 'föobar'"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config.set_rule_option('title-max-length', u'föobar', 60)
# invalid option value
- expected_error_msg = u"'föo' is not a valid value for option 'title-max-length.line-length'. " + \
- u"Option 'line-length' must be a positive integer (current value: 'föo')."
+ expected_error_msg = "'föo' is not a valid value for option 'title-max-length.line-length'. " + \
+ "Option 'line-length' must be a positive integer (current value: 'föo')."
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
- config.set_rule_option('title-max-length', 'line-length', u"föo")
+ config.set_rule_option('title-max-length', 'line-length', "föo")
def test_set_general_option(self):
config = LintConfig()
@@ -117,7 +112,7 @@ class LintConfigTests(BaseTestCase):
actual_rule = config.rules.find_rule("contrib-title-conventional-commits")
self.assertTrue(actual_rule.is_contrib)
- self.assertEqual(ustr(type(actual_rule)), "<class 'conventional_commit.ConventionalCommit'>")
+ self.assertEqual(str(type(actual_rule)), "<class 'conventional_commit.ConventionalCommit'>")
self.assertEqual(actual_rule.id, 'CT1')
self.assertEqual(actual_rule.name, u'contrib-title-conventional-commits')
self.assertEqual(actual_rule.target, rules.CommitMessageTitle)
@@ -135,7 +130,7 @@ class LintConfigTests(BaseTestCase):
actual_rule = config.rules.find_rule("contrib-body-requires-signed-off-by")
self.assertTrue(actual_rule.is_contrib)
- self.assertEqual(ustr(type(actual_rule)), "<class 'signedoff_by.SignedOffBy'>")
+ self.assertEqual(str(type(actual_rule)), "<class 'signedoff_by.SignedOffBy'>")
self.assertEqual(actual_rule.id, 'CC1')
self.assertEqual(actual_rule.name, u'contrib-body-requires-signed-off-by')
@@ -151,15 +146,15 @@ class LintConfigTests(BaseTestCase):
def test_contrib_negative(self):
config = LintConfig()
# non-existent contrib rule
- with self.assertRaisesMessage(LintConfigError, u"No contrib rule with id or name 'föo' found."):
- config.contrib = u"contrib-title-conventional-commits,föo"
+ with self.assertRaisesMessage(LintConfigError, "No contrib rule with id or name 'föo' found."):
+ config.contrib = "contrib-title-conventional-commits,föo"
# UserRuleError, RuleOptionError should be re-raised as LintConfigErrors
- side_effects = [rules.UserRuleError(u"üser-rule"), options.RuleOptionError(u"rüle-option")]
+ side_effects = [rules.UserRuleError("üser-rule"), options.RuleOptionError("rüle-option")]
for side_effect in side_effects:
with patch('gitlint.config.rule_finder.find_rule_classes', side_effect=side_effect):
- with self.assertRaisesMessage(LintConfigError, ustr(side_effect)):
- config.contrib = u"contrib-title-conventional-commits"
+ with self.assertRaisesMessage(LintConfigError, str(side_effect)):
+ config.contrib = "contrib-title-conventional-commits"
def test_extra_path(self):
config = LintConfig()
@@ -168,11 +163,11 @@ class LintConfigTests(BaseTestCase):
self.assertEqual(config.extra_path, self.get_user_rules_path())
actual_rule = config.rules.find_rule('UC1')
self.assertTrue(actual_rule.is_user_defined)
- self.assertEqual(ustr(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>")
+ self.assertEqual(str(type(actual_rule)), "<class 'my_commit_rules.MyUserCommitRule'>")
self.assertEqual(actual_rule.id, 'UC1')
self.assertEqual(actual_rule.name, u'my-üser-commit-rule')
self.assertEqual(actual_rule.target, None)
- expected_rule_option = options.IntOption('violation-count', 1, u"Number of violåtions to return")
+ expected_rule_option = options.IntOption('violation-count', 1, "Number of violåtions to return")
self.assertListEqual(actual_rule.options_spec, [expected_rule_option])
self.assertDictEqual(actual_rule.options, {'violation-count': expected_rule_option})
@@ -183,10 +178,10 @@ class LintConfigTests(BaseTestCase):
def test_extra_path_negative(self):
config = LintConfig()
- regex = u"Option extra-path must be either an existing directory or file (current value: 'föo/bar')"
+ regex = "Option extra-path must be either an existing directory or file (current value: 'föo/bar')"
# incorrect extra_path
with self.assertRaisesMessage(LintConfigError, regex):
- config.extra_path = u"föo/bar"
+ config.extra_path = "föo/bar"
# extra path contains classes with errors
with self.assertRaisesMessage(LintConfigError,
@@ -198,17 +193,17 @@ class LintConfigTests(BaseTestCase):
# Note that we shouldn't test whether we can set unicode because python just doesn't allow unicode attributes
with self.assertRaisesMessage(LintConfigError, "'foo' is not a valid gitlint option"):
- config.set_general_option("foo", u"bår")
+ config.set_general_option("foo", "bår")
# try setting _config_path, this is a real attribute of LintConfig, but the code should prevent it from
# being set
with self.assertRaisesMessage(LintConfigError, "'_config_path' is not a valid gitlint option"):
- config.set_general_option("_config_path", u"bår")
+ config.set_general_option("_config_path", "bår")
# invalid verbosity
- incorrect_values = [-1, u"föo"]
+ incorrect_values = [-1, "föo"]
for value in incorrect_values:
- expected_msg = u"Option 'verbosity' must be a positive integer (current value: '{0}')".format(value)
+ expected_msg = f"Option 'verbosity' must be a positive integer (current value: '{value}')"
with self.assertRaisesMessage(LintConfigError, expected_msg):
config.verbosity = value
@@ -220,12 +215,12 @@ class LintConfigTests(BaseTestCase):
# invalid ignore_xxx_commits
ignore_attributes = ["ignore_merge_commits", "ignore_fixup_commits", "ignore_squash_commits",
"ignore_revert_commits"]
- incorrect_values = [-1, 4, u"föo"]
+ incorrect_values = [-1, 4, "föo"]
for attribute in ignore_attributes:
for value in incorrect_values:
option_name = attribute.replace("_", "-")
with self.assertRaisesMessage(LintConfigError,
- "Option '{0}' must be either 'true' or 'false'".format(option_name)):
+ f"Option '{option_name}' must be either 'true' or 'false'"):
setattr(config, attribute, value)
# invalid ignore -> not here because ignore is a ListOption which converts everything to a string before
@@ -235,15 +230,15 @@ class LintConfigTests(BaseTestCase):
for attribute in ['debug', 'staged', 'ignore_stdin']:
option_name = attribute.replace("_", "-")
with self.assertRaisesMessage(LintConfigError,
- "Option '{0}' must be either 'true' or 'false'".format(option_name)):
- setattr(config, attribute, u"föobar")
+ f"Option '{option_name}' must be either 'true' or 'false'"):
+ setattr(config, attribute, "föobar")
# extra-path has its own negative test
# invalid target
with self.assertRaisesMessage(LintConfigError,
- u"Option target must be an existing directory (current value: 'föo/bar')"):
- config.target = u"föo/bar"
+ "Option target must be an existing directory (current value: 'föo/bar')"):
+ config.target = "föo/bar"
def test_ignore_independent_from_rules(self):
# Test that the lintconfig rules are not modified when setting config.ignore
@@ -273,9 +268,9 @@ class LintConfigTests(BaseTestCase):
# Other attributes don't matter
config1 = LintConfig()
config2 = LintConfig()
- config1.foo = u"bår"
+ config1.foo = "bår"
self.assertEqual(config1, config2)
- config2.foo = u"dūr"
+ config2.foo = "dūr"
self.assertEqual(config1, config2)
@@ -283,5 +278,5 @@ class LintConfigGeneratorTests(BaseTestCase):
@staticmethod
@patch('gitlint.config.shutil.copyfile')
def test_install_commit_msg_hook_negative(copy):
- LintConfigGenerator.generate_config(u"föo/bar/test")
- copy.assert_called_with(GITLINT_CONFIG_TEMPLATE_SRC_PATH, u"föo/bar/test")
+ LintConfigGenerator.generate_config("föo/bar/test")
+ copy.assert_called_with(GITLINT_CONFIG_TEMPLATE_SRC_PATH, "föo/bar/test")
diff --git a/gitlint/tests/config/test_config_builder.py b/gitlint/tests/config/test_config_builder.py
index 5a28c9f..e0d7f9b 100644
--- a/gitlint/tests/config/test_config_builder.py
+++ b/gitlint/tests/config/test_config_builder.py
@@ -42,30 +42,30 @@ class LintConfigBuilderTests(BaseTestCase):
config_builder = LintConfigBuilder()
# nothing gitlint
- config_builder.set_config_from_commit(self.gitcommit(u"tëst\ngitlint\nfoo"))
+ config_builder.set_config_from_commit(self.gitcommit("tëst\ngitlint\nfoo"))
config = config_builder.build()
self.assertSequenceEqual(config.rules, original_rules)
self.assertListEqual(config.ignore, [])
# ignore all rules
- config_builder.set_config_from_commit(self.gitcommit(u"tëst\ngitlint-ignore: all\nfoo"))
+ config_builder.set_config_from_commit(self.gitcommit("tëst\ngitlint-ignore: all\nfoo"))
config = config_builder.build()
self.assertEqual(config.ignore, original_rule_ids)
# ignore all rules, no space
- config_builder.set_config_from_commit(self.gitcommit(u"tëst\ngitlint-ignore:all\nfoo"))
+ config_builder.set_config_from_commit(self.gitcommit("tëst\ngitlint-ignore:all\nfoo"))
config = config_builder.build()
self.assertEqual(config.ignore, original_rule_ids)
# ignore all rules, more spacing
- config_builder.set_config_from_commit(self.gitcommit(u"tëst\ngitlint-ignore: \t all\nfoo"))
+ config_builder.set_config_from_commit(self.gitcommit("tëst\ngitlint-ignore: \t all\nfoo"))
config = config_builder.build()
self.assertEqual(config.ignore, original_rule_ids)
def test_set_from_commit_ignore_specific(self):
# ignore specific rules
config_builder = LintConfigBuilder()
- config_builder.set_config_from_commit(self.gitcommit(u"tëst\ngitlint-ignore: T1, body-hard-tab"))
+ config_builder.set_config_from_commit(self.gitcommit("tëst\ngitlint-ignore: T1, body-hard-tab"))
config = config_builder.build()
self.assertEqual(config.ignore, ["T1", "body-hard-tab"])
@@ -89,14 +89,14 @@ class LintConfigBuilderTests(BaseTestCase):
config_builder = LintConfigBuilder()
# bad config file load
- foo_path = self.get_sample_path(u"föo")
- expected_error_msg = u"Invalid file path: {0}".format(foo_path)
+ foo_path = self.get_sample_path("föo")
+ expected_error_msg = f"Invalid file path: {foo_path}"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config_builder.set_from_config_file(foo_path)
# error during file parsing
path = self.get_sample_path("config/no-sections")
- expected_error_msg = u"File contains no section headers."
+ expected_error_msg = "File contains no section headers."
# We only match the start of the message here, since the exact message can vary depending on platform
with self.assertRaisesRegex(LintConfigError, expected_error_msg):
config_builder.set_from_config_file(path)
@@ -105,7 +105,7 @@ class LintConfigBuilderTests(BaseTestCase):
path = self.get_sample_path("config/nonexisting-rule")
config_builder = LintConfigBuilder()
config_builder.set_from_config_file(path)
- expected_error_msg = u"No such rule 'föobar'"
+ expected_error_msg = "No such rule 'föobar'"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config_builder.build()
@@ -113,7 +113,7 @@ class LintConfigBuilderTests(BaseTestCase):
path = self.get_sample_path("config/nonexisting-general-option")
config_builder = LintConfigBuilder()
config_builder.set_from_config_file(path)
- expected_error_msg = u"'foo' is not a valid gitlint option"
+ expected_error_msg = "'foo' is not a valid gitlint option"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config_builder.build()
@@ -121,7 +121,7 @@ class LintConfigBuilderTests(BaseTestCase):
path = self.get_sample_path("config/nonexisting-option")
config_builder = LintConfigBuilder()
config_builder.set_from_config_file(path)
- expected_error_msg = u"Rule 'title-max-length' has no option 'föobar'"
+ expected_error_msg = "Rule 'title-max-length' has no option 'föobar'"
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config_builder.build()
@@ -129,8 +129,8 @@ class LintConfigBuilderTests(BaseTestCase):
path = self.get_sample_path("config/invalid-option-value")
config_builder = LintConfigBuilder()
config_builder.set_from_config_file(path)
- expected_error_msg = u"'föo' is not a valid value for option 'title-max-length.line-length'. " + \
- u"Option 'line-length' must be a positive integer (current value: 'föo')."
+ expected_error_msg = "'föo' is not a valid value for option 'title-max-length.line-length'. " + \
+ "Option 'line-length' must be a positive integer (current value: 'föo')."
with self.assertRaisesMessage(LintConfigError, expected_error_msg):
config_builder.build()
@@ -141,39 +141,39 @@ class LintConfigBuilderTests(BaseTestCase):
config_builder = LintConfigBuilder()
config_builder.set_config_from_string_list(['general.verbosity=1', 'title-max-length.line-length=60',
'body-max-line-length.line-length=120',
- u"title-must-not-contain-word.words=håha"])
+ "title-must-not-contain-word.words=håha"])
config = config_builder.build()
self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 60)
self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 120)
- self.assertListEqual(config.get_rule_option('title-must-not-contain-word', 'words'), [u"håha"])
+ self.assertListEqual(config.get_rule_option('title-must-not-contain-word', 'words'), ["håha"])
self.assertEqual(config.verbosity, 1)
def test_set_config_from_string_list_negative(self):
config_builder = LintConfigBuilder()
# assert error on incorrect rule - this happens at build time
- config_builder.set_config_from_string_list([u"föo.bar=1"])
- with self.assertRaisesMessage(LintConfigError, u"No such rule 'föo'"):
+ config_builder.set_config_from_string_list(["föo.bar=1"])
+ with self.assertRaisesMessage(LintConfigError, "No such rule 'föo'"):
config_builder.build()
# no equal sign
- expected_msg = u"'föo.bar' is an invalid configuration option. Use '<rule>.<option>=<value>'"
+ expected_msg = "'föo.bar' is an invalid configuration option. Use '<rule>.<option>=<value>'"
with self.assertRaisesMessage(LintConfigError, expected_msg):
- config_builder.set_config_from_string_list([u"föo.bar"])
+ config_builder.set_config_from_string_list(["föo.bar"])
# missing value
- expected_msg = u"'föo.bar=' is an invalid configuration option. Use '<rule>.<option>=<value>'"
+ expected_msg = "'föo.bar=' is an invalid configuration option. Use '<rule>.<option>=<value>'"
with self.assertRaisesMessage(LintConfigError, expected_msg):
- config_builder.set_config_from_string_list([u"föo.bar="])
+ config_builder.set_config_from_string_list(["föo.bar="])
# space instead of equal sign
- expected_msg = u"'föo.bar 1' is an invalid configuration option. Use '<rule>.<option>=<value>'"
+ expected_msg = "'föo.bar 1' is an invalid configuration option. Use '<rule>.<option>=<value>'"
with self.assertRaisesMessage(LintConfigError, expected_msg):
- config_builder.set_config_from_string_list([u"föo.bar 1"])
+ config_builder.set_config_from_string_list(["föo.bar 1"])
# no period between rule and option names
- expected_msg = u"'föobar=1' is an invalid configuration option. Use '<rule>.<option>=<value>'"
+ expected_msg = "'föobar=1' is an invalid configuration option. Use '<rule>.<option>=<value>'"
with self.assertRaisesMessage(LintConfigError, expected_msg):
config_builder.set_config_from_string_list([u'föobar=1'])
@@ -216,15 +216,15 @@ class LintConfigBuilderTests(BaseTestCase):
# Add a named rule by setting an option in the config builder that follows the named rule pattern
# Assert that whitespace in the rule name is stripped
rule_qualifiers = [u'T7:my-extra-rüle', u' T7 : my-extra-rüle ', u'\tT7:\tmy-extra-rüle\t',
- u'T7:\t\n \tmy-extra-rüle\t\n\n', u"title-match-regex:my-extra-rüle"]
+ u'T7:\t\n \tmy-extra-rüle\t\n\n', "title-match-regex:my-extra-rüle"]
for rule_qualifier in rule_qualifiers:
config_builder = LintConfigBuilder()
- config_builder.set_option(rule_qualifier, 'regex', u"föo")
+ config_builder.set_option(rule_qualifier, 'regex', "föo")
expected_rules = copy.deepcopy(default_rules)
- my_rule = rules.TitleRegexMatches({'regex': u"föo"})
- my_rule.id = rules.TitleRegexMatches.id + u":my-extra-rüle"
- my_rule.name = rules.TitleRegexMatches.name + u":my-extra-rüle"
+ my_rule = rules.TitleRegexMatches({'regex': "föo"})
+ my_rule.id = rules.TitleRegexMatches.id + ":my-extra-rüle"
+ my_rule.name = rules.TitleRegexMatches.name + ":my-extra-rüle"
expected_rules._rules[u'T7:my-extra-rüle'] = my_rule
self.assertEqual(config_builder.build().rules, expected_rules)
@@ -233,32 +233,32 @@ class LintConfigBuilderTests(BaseTestCase):
# to the same rule
for other_rule_qualifier in rule_qualifiers:
cb = config_builder.clone()
- cb.set_option(other_rule_qualifier, 'regex', other_rule_qualifier + u"bōr")
+ cb.set_option(other_rule_qualifier, 'regex', other_rule_qualifier + "bōr")
# before setting the expected rule option value correctly, the RuleCollection should be different
self.assertNotEqual(cb.build().rules, expected_rules)
# after setting the option on the expected rule, it should be equal
- my_rule.options['regex'].set(other_rule_qualifier + u"bōr")
+ my_rule.options['regex'].set(other_rule_qualifier + "bōr")
self.assertEqual(cb.build().rules, expected_rules)
- my_rule.options['regex'].set(u"wrong")
+ my_rule.options['regex'].set("wrong")
def test_named_rules_negative(self):
# T7 = title-match-regex
# Invalid rule name
- for invalid_name in ["", " ", " ", "\t", "\n", u"å b", u"å:b", u"åb:", u":åb"]:
+ for invalid_name in ["", " ", " ", "\t", "\n", "å b", "å:b", "åb:", ":åb"]:
config_builder = LintConfigBuilder()
- config_builder.set_option(u"T7:{0}".format(invalid_name), 'regex', u"tëst")
- expected_msg = u"The rule-name part in 'T7:{0}' cannot contain whitespace, colons or be empty"
- with self.assertRaisesMessage(LintConfigError, expected_msg.format(invalid_name)):
+ config_builder.set_option(f"T7:{invalid_name}", 'regex', "tëst")
+ expected_msg = f"The rule-name part in 'T7:{invalid_name}' cannot contain whitespace, colons or be empty"
+ with self.assertRaisesMessage(LintConfigError, expected_msg):
config_builder.build()
# Invalid parent rule name
config_builder = LintConfigBuilder()
- config_builder.set_option(u"Ž123:foöbar", u"fåke-option", u"fåke-value")
- with self.assertRaisesMessage(LintConfigError, u"No such rule 'Ž123' (named rule: 'Ž123:foöbar')"):
+ config_builder.set_option("Ž123:foöbar", "fåke-option", "fåke-value")
+ with self.assertRaisesMessage(LintConfigError, "No such rule 'Ž123' (named rule: 'Ž123:foöbar')"):
config_builder.build()
# Invalid option name (this is the same as with regular rules)
config_builder = LintConfigBuilder()
- config_builder.set_option(u"T7:foöbar", u"blå", u"my-rëgex")
- with self.assertRaisesMessage(LintConfigError, u"Rule 'T7:foöbar' has no option 'blå'"):
+ config_builder.set_option("T7:foöbar", "blå", "my-rëgex")
+ with self.assertRaisesMessage(LintConfigError, "Rule 'T7:foöbar' has no option 'blå'"):
config_builder.build()
diff --git a/gitlint/tests/config/test_config_precedence.py b/gitlint/tests/config/test_config_precedence.py
index a0eeccd..aa4de88 100644
--- a/gitlint/tests/config/test_config_precedence.py
+++ b/gitlint/tests/config/test_config_precedence.py
@@ -1,20 +1,10 @@
# -*- coding: utf-8 -*-
-try:
- # python 2.x
- from StringIO import StringIO
-except ImportError:
- # python 3.x
- from io import StringIO
+from io import StringIO
from click.testing import CliRunner
-try:
- # python 2.x
- from mock import patch
-except ImportError:
- # python 3.x
- from unittest.mock import patch # pylint: disable=no-name-in-module, import-error
+from unittest.mock import patch
from gitlint.tests.base import BaseTestCase
from gitlint import cli
@@ -25,7 +15,7 @@ class LintConfigPrecedenceTests(BaseTestCase):
def setUp(self):
self.cli = CliRunner()
- @patch('gitlint.cli.get_stdin_data', return_value=u"WIP:fö\n\nThis is å test message\n")
+ @patch('gitlint.cli.get_stdin_data', return_value="WIP:fö\n\nThis is å test message\n")
def test_config_precedence(self, _):
# TODO(jroovers): this test really only test verbosity, we need to do some refactoring to gitlint.cli
# to more easily test everything
@@ -41,14 +31,14 @@ class LintConfigPrecedenceTests(BaseTestCase):
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["-vvv", "-c", "general.verbosity=2", "--config", config_path])
self.assertEqual(result.output, "")
- self.assertEqual(stderr.getvalue(), u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
+ self.assertEqual(stderr.getvalue(), "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
# 2. environment variables
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["-c", "general.verbosity=2", "--config", config_path],
env={"GITLINT_VERBOSITY": "3"})
self.assertEqual(result.output, "")
- self.assertEqual(stderr.getvalue(), u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
+ self.assertEqual(stderr.getvalue(), "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
# 3. commandline -c flags
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
@@ -66,9 +56,9 @@ class LintConfigPrecedenceTests(BaseTestCase):
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli)
self.assertEqual(result.output, "")
- self.assertEqual(stderr.getvalue(), u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
+ self.assertEqual(stderr.getvalue(), "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
- @patch('gitlint.cli.get_stdin_data', return_value=u"WIP: This is å test")
+ @patch('gitlint.cli.get_stdin_data', return_value="WIP: This is å test")
def test_ignore_precedence(self, get_stdin_data):
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
# --ignore takes precedence over -c general.ignore
@@ -77,11 +67,11 @@ class LintConfigPrecedenceTests(BaseTestCase):
self.assertEqual(result.exit_code, 1)
# We still expect the T5 violation, but no B6 violation as --ignore overwrites -c general.ignore
self.assertEqual(stderr.getvalue(),
- u"1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is å test\"\n")
+ "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is å test\"\n")
# test that we can also still configure a rule that is first ignored but then not
with patch('gitlint.display.stderr', new=StringIO()) as stderr:
- get_stdin_data.return_value = u"This is å test"
+ get_stdin_data.return_value = "This is å test"
# --ignore takes precedence over -c general.ignore
result = self.cli.invoke(cli.cli, ["-c", "general.ignore=title-max-length",
"-c", "title-max-length.line-length=5",
@@ -91,7 +81,7 @@ class LintConfigPrecedenceTests(BaseTestCase):
# We still expect the T1 violation with custom config,
# but no B6 violation as --ignore overwrites -c general.ignore
- self.assertEqual(stderr.getvalue(), u"1: T1 Title exceeds max length (14>5): \"This is å test\"\n")
+ self.assertEqual(stderr.getvalue(), "1: T1 Title exceeds max length (14>5): \"This is å test\"\n")
def test_general_option_after_rule_option(self):
# We used to have a bug where we didn't process general options before setting specific options, this would
diff --git a/gitlint/tests/config/test_rule_collection.py b/gitlint/tests/config/test_rule_collection.py
index 089992c..5a50be0 100644
--- a/gitlint/tests/config/test_rule_collection.py
+++ b/gitlint/tests/config/test_rule_collection.py
@@ -10,34 +10,34 @@ class RuleCollectionTests(BaseTestCase):
def test_add_rule(self):
collection = RuleCollection()
- collection.add_rule(rules.TitleMaxLength, u"my-rüle", {"my_attr": u"föo", "my_attr2": 123})
+ collection.add_rule(rules.TitleMaxLength, "my-rüle", {"my_attr": "föo", "my_attr2": 123})
expected = rules.TitleMaxLength()
- expected.id = u"my-rüle"
- expected.my_attr = u"föo"
+ expected.id = "my-rüle"
+ expected.my_attr = "föo"
expected.my_attr2 = 123
self.assertEqual(len(collection), 1)
- self.assertDictEqual(collection._rules, OrderedDict({u"my-rüle": expected}))
+ self.assertDictEqual(collection._rules, OrderedDict({"my-rüle": expected}))
# Need to explicitely compare expected attributes as the rule.__eq__ method does not compare these attributes
self.assertEqual(collection._rules[expected.id].my_attr, expected.my_attr)
self.assertEqual(collection._rules[expected.id].my_attr2, expected.my_attr2)
def test_add_find_rule(self):
collection = RuleCollection()
- collection.add_rules([rules.TitleMaxLength, rules.TitleTrailingWhitespace], {"my_attr": u"föo"})
+ collection.add_rules([rules.TitleMaxLength, rules.TitleTrailingWhitespace], {"my_attr": "föo"})
# find by id
expected = rules.TitleMaxLength()
rule = collection.find_rule('T1')
self.assertEqual(rule, expected)
- self.assertEqual(rule.my_attr, u"föo")
+ self.assertEqual(rule.my_attr, "föo")
# find by name
expected2 = rules.TitleTrailingWhitespace()
rule = collection.find_rule('title-trailing-whitespace')
self.assertEqual(rule, expected2)
- self.assertEqual(rule.my_attr, u"föo")
+ self.assertEqual(rule.my_attr, "föo")
# find non-existing
rule = collection.find_rule(u'föo')
@@ -45,8 +45,8 @@ class RuleCollectionTests(BaseTestCase):
def test_delete_rules_by_attr(self):
collection = RuleCollection()
- collection.add_rules([rules.TitleMaxLength, rules.TitleTrailingWhitespace], {"foo": u"bår"})
- collection.add_rules([rules.BodyHardTab], {"hur": u"dûr"})
+ collection.add_rules([rules.TitleMaxLength, rules.TitleTrailingWhitespace], {"foo": "bår"})
+ collection.add_rules([rules.BodyHardTab], {"hur": "dûr"})
# Assert all rules are there as expected
self.assertEqual(len(collection), 3)
@@ -54,11 +54,11 @@ class RuleCollectionTests(BaseTestCase):
self.assertEqual(collection.find_rule(expected_rule.id), expected_rule)
# Delete rules by attr, assert that we still have the right rules in the collection
- collection.delete_rules_by_attr("foo", u"bår")
+ collection.delete_rules_by_attr("foo", "bår")
self.assertEqual(len(collection), 1)
self.assertIsNone(collection.find_rule(rules.TitleMaxLength.id), None)
self.assertIsNone(collection.find_rule(rules.TitleTrailingWhitespace.id), None)
found = collection.find_rule(rules.BodyHardTab.id)
self.assertEqual(found, rules.BodyHardTab())
- self.assertEqual(found.hur, u"dûr")
+ self.assertEqual(found.hur, "dûr")