summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/tests/config
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint-core/gitlint/tests/config')
-rw-r--r--gitlint-core/gitlint/tests/config/test_config.py109
-rw-r--r--gitlint-core/gitlint/tests/config/test_config_builder.py88
-rw-r--r--gitlint-core/gitlint/tests/config/test_config_precedence.py46
-rw-r--r--gitlint-core/gitlint/tests/config/test_rule_collection.py9
4 files changed, 147 insertions, 105 deletions
diff --git a/gitlint-core/gitlint/tests/config/test_config.py b/gitlint-core/gitlint/tests/config/test_config.py
index c3fd78a..852bf75 100644
--- a/gitlint-core/gitlint/tests/config/test_config.py
+++ b/gitlint-core/gitlint/tests/config/test_config.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from unittest.mock import patch
from gitlint import rules
@@ -9,16 +7,15 @@ from gitlint.tests.base import BaseTestCase
class LintConfigTests(BaseTestCase):
-
def test_set_rule_option(self):
config = LintConfig()
# assert default title line-length
- self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 72)
+ self.assertEqual(config.get_rule_option("title-max-length", "line-length"), 72)
# change line length and assert it is set
- config.set_rule_option('title-max-length', 'line-length', 60)
- self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 60)
+ config.set_rule_option("title-max-length", "line-length", 60)
+ self.assertEqual(config.get_rule_option("title-max-length", "line-length"), 60)
def test_set_rule_option_negative(self):
config = LintConfig()
@@ -26,18 +23,20 @@ class LintConfigTests(BaseTestCase):
# non-existing rule
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)
+ config.set_rule_option("föobar", "lïne-length", 60)
# non-existing option
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)
+ config.set_rule_option("title-max-length", "föobar", 60)
# invalid option value
- 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')."
+ 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', "föo")
+ config.set_rule_option("title-max-length", "line-length", "föo")
def test_set_general_option(self):
config = LintConfig()
@@ -45,12 +44,14 @@ class LintConfigTests(BaseTestCase):
# Check that default general options are correct
self.assertTrue(config.ignore_merge_commits)
self.assertTrue(config.ignore_fixup_commits)
+ self.assertTrue(config.ignore_fixup_amend_commits)
self.assertTrue(config.ignore_squash_commits)
self.assertTrue(config.ignore_revert_commits)
self.assertFalse(config.ignore_stdin)
self.assertFalse(config.staged)
self.assertFalse(config.fail_without_commits)
+ self.assertFalse(config.regex_style_search)
self.assertFalse(config.debug)
self.assertEqual(config.verbosity, 3)
active_rule_classes = tuple(type(rule) for rule in config.rules)
@@ -76,6 +77,10 @@ class LintConfigTests(BaseTestCase):
config.set_general_option("ignore-fixup-commits", "false")
self.assertFalse(config.ignore_fixup_commits)
+ # ignore_fixup_amend_commit
+ config.set_general_option("ignore-fixup-amend-commits", "false")
+ self.assertFalse(config.ignore_fixup_amend_commits)
+
# ignore_squash_commit
config.set_general_option("ignore-squash-commits", "false")
self.assertFalse(config.ignore_squash_commits)
@@ -100,6 +105,10 @@ class LintConfigTests(BaseTestCase):
config.set_general_option("fail-without-commits", "true")
self.assertTrue(config.fail_without_commits)
+ # regex-style-search
+ config.set_general_option("regex-style-search", "true")
+ self.assertTrue(config.regex_style_search)
+
# target
config.set_general_option("target", self.SAMPLES_DIR)
self.assertEqual(config.target, self.SAMPLES_DIR)
@@ -118,8 +127,8 @@ class LintConfigTests(BaseTestCase):
self.assertTrue(actual_rule.is_contrib)
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.id, "CT1")
+ self.assertEqual(actual_rule.name, "contrib-title-conventional-commits")
self.assertEqual(actual_rule.target, rules.CommitMessageTitle)
expected_rule_option = options.ListOption(
@@ -129,15 +138,15 @@ class LintConfigTests(BaseTestCase):
)
self.assertListEqual(actual_rule.options_spec, [expected_rule_option])
- self.assertDictEqual(actual_rule.options, {'types': expected_rule_option})
+ self.assertDictEqual(actual_rule.options, {"types": expected_rule_option})
# Check contrib-body-requires-signed-off-by contrib rule
actual_rule = config.rules.find_rule("contrib-body-requires-signed-off-by")
self.assertTrue(actual_rule.is_contrib)
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')
+ self.assertEqual(actual_rule.id, "CC1")
+ self.assertEqual(actual_rule.name, "contrib-body-requires-signed-off-by")
# reset value (this is a different code path)
config.set_general_option("contrib", "contrib-body-requires-signed-off-by")
@@ -157,7 +166,7 @@ class LintConfigTests(BaseTestCase):
# UserRuleError, RuleOptionError should be re-raised as LintConfigErrors
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 patch("gitlint.config.rule_finder.find_rule_classes", side_effect=side_effect):
with self.assertRaisesMessage(LintConfigError, str(side_effect)):
config.contrib = "contrib-title-conventional-commits"
@@ -166,15 +175,15 @@ class LintConfigTests(BaseTestCase):
config.set_general_option("extra-path", self.get_user_rules_path())
self.assertEqual(config.extra_path, self.get_user_rules_path())
- actual_rule = config.rules.find_rule('UC1')
+ actual_rule = config.rules.find_rule("UC1")
self.assertTrue(actual_rule.is_user_defined)
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.id, "UC1")
+ self.assertEqual(actual_rule.name, "my-üser-commit-rule")
self.assertEqual(actual_rule.target, None)
- expected_rule_option = options.IntOption('violation-count', 1, "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})
+ self.assertDictEqual(actual_rule.options, {"violation-count": expected_rule_option})
# reset value (this is a different code path)
config.set_general_option("extra-path", self.SAMPLES_DIR)
@@ -189,8 +198,9 @@ class LintConfigTests(BaseTestCase):
config.extra_path = "föo/bar"
# extra path contains classes with errors
- with self.assertRaisesMessage(LintConfigError,
- "User-defined rule class 'MyUserLineRule' must have a 'validate' method"):
+ with self.assertRaisesMessage(
+ LintConfigError, "User-defined rule class 'MyUserLineRule' must have a 'validate' method"
+ ):
config.extra_path = self.get_sample_path("user_rules/incorrect_linerule")
def test_set_general_option_negative(self):
@@ -218,31 +228,37 @@ class LintConfigTests(BaseTestCase):
config.verbosity = value
# invalid ignore_xxx_commits
- ignore_attributes = ["ignore_merge_commits", "ignore_fixup_commits", "ignore_squash_commits",
- "ignore_revert_commits"]
+ ignore_attributes = [
+ "ignore_merge_commits",
+ "ignore_fixup_commits",
+ "ignore_fixup_amend_commits",
+ "ignore_squash_commits",
+ "ignore_revert_commits",
+ ]
incorrect_values = [-1, 4, "föo"]
for attribute in ignore_attributes:
for value in incorrect_values:
option_name = attribute.replace("_", "-")
- with self.assertRaisesMessage(LintConfigError,
- f"Option '{option_name}' must be either 'true' or 'false'"):
+ with self.assertRaisesMessage(
+ LintConfigError, 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
# splitting which means it it will accept just about everything
# invalid boolean options
- for attribute in ['debug', 'staged', 'ignore_stdin', 'fail_without_commits']:
+ for attribute in ["debug", "staged", "ignore_stdin", "fail_without_commits", "regex_style_search"]:
option_name = attribute.replace("_", "-")
- with self.assertRaisesMessage(LintConfigError,
- f"Option '{option_name}' must be either 'true' or 'false'"):
+ with self.assertRaisesMessage(LintConfigError, 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,
- "Option target must be an existing directory (current value: 'föo/bar')"):
+ with self.assertRaisesMessage(
+ LintConfigError, "Option target must be an existing directory (current value: 'föo/bar')"
+ ):
config.target = "föo/bar"
def test_ignore_independent_from_rules(self):
@@ -259,12 +275,25 @@ class LintConfigTests(BaseTestCase):
self.assertNotEqual(LintConfig(), LintConfigGenerator())
# Ensure LintConfig are not equal if they differ on their attributes
- attrs = [("verbosity", 1), ("rules", []), ("ignore_stdin", True), ("debug", True),
- ("ignore", ["T1"]), ("staged", True), ("_config_path", self.get_sample_path()),
- ("ignore_merge_commits", False), ("ignore_fixup_commits", False),
- ("ignore_squash_commits", False), ("ignore_revert_commits", False),
- ("extra_path", self.get_sample_path("user_rules")), ("target", self.get_sample_path()),
- ("contrib", ["CC1"])]
+ attrs = [
+ ("verbosity", 1),
+ ("rules", []),
+ ("ignore_stdin", True),
+ ("fail_without_commits", True),
+ ("regex_style_search", True),
+ ("debug", True),
+ ("ignore", ["T1"]),
+ ("staged", True),
+ ("_config_path", self.get_sample_path()),
+ ("ignore_merge_commits", False),
+ ("ignore_fixup_commits", False),
+ ("ignore_fixup_amend_commits", False),
+ ("ignore_squash_commits", False),
+ ("ignore_revert_commits", False),
+ ("extra_path", self.get_sample_path("user_rules")),
+ ("target", self.get_sample_path()),
+ ("contrib", ["CC1"]),
+ ]
for attr, val in attrs:
config = LintConfig()
setattr(config, attr, val)
@@ -281,7 +310,7 @@ class LintConfigTests(BaseTestCase):
class LintConfigGeneratorTests(BaseTestCase):
@staticmethod
- @patch('gitlint.config.shutil.copyfile')
+ @patch("gitlint.config.shutil.copyfile")
def test_install_commit_msg_hook_negative(copy):
LintConfigGenerator.generate_config("föo/bar/test")
copy.assert_called_with(GITLINT_CONFIG_TEMPLATE_SRC_PATH, "föo/bar/test")
diff --git a/gitlint-core/gitlint/tests/config/test_config_builder.py b/gitlint-core/gitlint/tests/config/test_config_builder.py
index e0d7f9b..dfb77cd 100644
--- a/gitlint-core/gitlint/tests/config/test_config_builder.py
+++ b/gitlint-core/gitlint/tests/config/test_config_builder.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
import copy
from gitlint.tests.base import BaseTestCase
@@ -14,24 +13,27 @@ class LintConfigBuilderTests(BaseTestCase):
config = config_builder.build()
# assert some defaults
- self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 72)
- self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 80)
- self.assertListEqual(config.get_rule_option('title-must-not-contain-word', 'words'), ["WIP"])
+ self.assertEqual(config.get_rule_option("title-max-length", "line-length"), 72)
+ self.assertEqual(config.get_rule_option("body-max-line-length", "line-length"), 80)
+ self.assertListEqual(config.get_rule_option("title-must-not-contain-word", "words"), ["WIP"])
self.assertEqual(config.verbosity, 3)
# Make some changes and check blueprint
- config_builder.set_option('title-max-length', 'line-length', 100)
- config_builder.set_option('general', 'verbosity', 2)
- config_builder.set_option('title-must-not-contain-word', 'words', ["foo", "bar"])
- expected_blueprint = {'title-must-not-contain-word': {'words': ['foo', 'bar']},
- 'title-max-length': {'line-length': 100}, 'general': {'verbosity': 2}}
+ config_builder.set_option("title-max-length", "line-length", 100)
+ config_builder.set_option("general", "verbosity", 2)
+ config_builder.set_option("title-must-not-contain-word", "words", ["foo", "bar"])
+ expected_blueprint = {
+ "title-must-not-contain-word": {"words": ["foo", "bar"]},
+ "title-max-length": {"line-length": 100},
+ "general": {"verbosity": 2},
+ }
self.assertDictEqual(config_builder._config_blueprint, expected_blueprint)
# Build config and verify that the changes have occurred and no other changes
config = config_builder.build()
- self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 100)
- self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 80) # should be unchanged
- self.assertListEqual(config.get_rule_option('title-must-not-contain-word', 'words'), ["foo", "bar"])
+ self.assertEqual(config.get_rule_option("title-max-length", "line-length"), 100)
+ self.assertEqual(config.get_rule_option("body-max-line-length", "line-length"), 80) # should be unchanged
+ self.assertListEqual(config.get_rule_option("title-must-not-contain-word", "words"), ["foo", "bar"])
self.assertEqual(config.verbosity, 2)
def test_set_from_commit_ignore_all(self):
@@ -82,8 +84,8 @@ class LintConfigBuilderTests(BaseTestCase):
self.assertIsNone(config.extra_path)
self.assertEqual(config.ignore, ["title-trailing-whitespace", "B2"])
- self.assertEqual(config.get_rule_option('title-max-length', 'line-length'), 20)
- self.assertEqual(config.get_rule_option('body-max-line-length', 'line-length'), 30)
+ self.assertEqual(config.get_rule_option("title-max-length", "line-length"), 20)
+ self.assertEqual(config.get_rule_option("body-max-line-length", "line-length"), 30)
def test_set_from_config_file_negative(self):
config_builder = LintConfigBuilder()
@@ -129,8 +131,10 @@ 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 = "'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')."
+ 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()
@@ -139,14 +143,19 @@ class LintConfigBuilderTests(BaseTestCase):
# change and assert changes
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',
- "title-must-not-contain-word.words=håha"])
+ config_builder.set_config_from_string_list(
+ [
+ "general.verbosity=1",
+ "title-max-length.line-length=60",
+ "body-max-line-length.line-length=120",
+ "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'), ["håha"])
+ 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"), ["håha"])
self.assertEqual(config.verbosity, 1)
def test_set_config_from_string_list_negative(self):
@@ -175,12 +184,12 @@ class LintConfigBuilderTests(BaseTestCase):
# no period between rule and option names
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'])
+ config_builder.set_config_from_string_list(["föobar=1"])
def test_rebuild_config(self):
# normal config build
config_builder = LintConfigBuilder()
- config_builder.set_option('general', 'verbosity', 3)
+ config_builder.set_option("general", "verbosity", 3)
lint_config = config_builder.build()
self.assertEqual(lint_config.verbosity, 3)
@@ -193,9 +202,9 @@ class LintConfigBuilderTests(BaseTestCase):
def test_clone(self):
config_builder = LintConfigBuilder()
- config_builder.set_option('general', 'verbosity', 2)
- config_builder.set_option('title-max-length', 'line-length', 100)
- expected = {'title-max-length': {'line-length': 100}, 'general': {'verbosity': 2}}
+ config_builder.set_option("general", "verbosity", 2)
+ config_builder.set_option("title-max-length", "line-length", 100)
+ expected = {"title-max-length": {"line-length": 100}, "general": {"verbosity": 2}}
self.assertDictEqual(config_builder._config_blueprint, expected)
# Clone and verify that the blueprint is the same as the original
@@ -203,7 +212,7 @@ class LintConfigBuilderTests(BaseTestCase):
self.assertDictEqual(cloned_builder._config_blueprint, expected)
# Modify the original and make sure we're not modifying the clone (i.e. check that the copy is a deep copy)
- config_builder.set_option('title-max-length', 'line-length', 120)
+ config_builder.set_option("title-max-length", "line-length", 120)
self.assertDictEqual(cloned_builder._config_blueprint, expected)
def test_named_rules(self):
@@ -215,17 +224,22 @@ 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', "title-match-regex:my-extra-rüle"]
+ rule_qualifiers = [
+ "T7:my-extra-rüle",
+ " T7 : my-extra-rüle ",
+ "\tT7:\tmy-extra-rüle\t",
+ "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', "föo")
+ config_builder.set_option(rule_qualifier, "regex", "föo")
expected_rules = copy.deepcopy(default_rules)
- my_rule = rules.TitleRegexMatches({'regex': "föo"})
+ 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
+ expected_rules._rules["T7:my-extra-rüle"] = my_rule
self.assertEqual(config_builder.build().rules, expected_rules)
# assert that changing an option on the newly added rule is passed correctly to the RuleCollection
@@ -233,20 +247,20 @@ 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 + "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 + "bōr")
+ my_rule.options["regex"].set(other_rule_qualifier + "bōr")
self.assertEqual(cb.build().rules, expected_rules)
- my_rule.options['regex'].set("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", "å b", "å:b", "åb:", ":åb"]:
config_builder = LintConfigBuilder()
- config_builder.set_option(f"T7:{invalid_name}", 'regex', "tëst")
+ 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()
diff --git a/gitlint-core/gitlint/tests/config/test_config_precedence.py b/gitlint-core/gitlint/tests/config/test_config_precedence.py
index aa4de88..22197e8 100644
--- a/gitlint-core/gitlint/tests/config/test_config_precedence.py
+++ b/gitlint-core/gitlint/tests/config/test_config_precedence.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from io import StringIO
from click.testing import CliRunner
@@ -13,9 +11,10 @@ from gitlint.config import LintConfigBuilder
class LintConfigPrecedenceTests(BaseTestCase):
def setUp(self):
+ super().setUp()
self.cli = CliRunner()
- @patch('gitlint.cli.get_stdin_data', return_value="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
@@ -28,60 +27,63 @@ class LintConfigPrecedenceTests(BaseTestCase):
config_path = self.get_sample_path("config/gitlintconfig")
# 1. commandline convenience flags
- with patch('gitlint.display.stderr', new=StringIO()) as stderr:
+ 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(), "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"})
+ 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(), "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:
+ with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["-c", "general.verbosity=2", "--config", config_path])
self.assertEqual(result.output, "")
self.assertEqual(stderr.getvalue(), "1: T5 Title contains the word 'WIP' (case-insensitive)\n")
# 4. config file
- with patch('gitlint.display.stderr', new=StringIO()) as stderr:
+ with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli, ["--config", config_path])
self.assertEqual(result.output, "")
self.assertEqual(stderr.getvalue(), "1: T5\n")
# 5. default config
- with patch('gitlint.display.stderr', new=StringIO()) as stderr:
+ with patch("gitlint.display.stderr", new=StringIO()) as stderr:
result = self.cli.invoke(cli.cli)
self.assertEqual(result.output, "")
self.assertEqual(stderr.getvalue(), "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP:fö\"\n")
- @patch('gitlint.cli.get_stdin_data', return_value="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:
+ with patch("gitlint.display.stderr", new=StringIO()) as stderr:
# --ignore takes precedence over -c general.ignore
result = self.cli.invoke(cli.cli, ["-c", "general.ignore=T5", "--ignore", "B6"])
self.assertEqual(result.output, "")
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(),
- "1: T5 Title contains the word 'WIP' (case-insensitive): \"WIP: This is å test\"\n")
+ self.assertEqual(
+ stderr.getvalue(), "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:
+ with patch("gitlint.display.stderr", new=StringIO()) as stderr:
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",
- "--ignore", "B6"])
+ result = self.cli.invoke(
+ cli.cli,
+ ["-c", "general.ignore=title-max-length", "-c", "title-max-length.line-length=5", "--ignore", "B6"],
+ )
self.assertEqual(result.output, "")
self.assertEqual(result.exit_code, 1)
# We still expect the T1 violation with custom config,
# but no B6 violation as --ignore overwrites -c general.ignore
- self.assertEqual(stderr.getvalue(), "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
@@ -89,10 +91,10 @@ class LintConfigPrecedenceTests(BaseTestCase):
# This test is here to test for regressions against this.
config_builder = LintConfigBuilder()
- config_builder.set_option(u'my-üser-commit-rule', 'violation-count', 3)
+ config_builder.set_option("my-üser-commit-rule", "violation-count", 3)
user_rules_path = self.get_sample_path("user_rules")
- config_builder.set_option('general', 'extra-path', user_rules_path)
+ config_builder.set_option("general", "extra-path", user_rules_path)
config = config_builder.build()
self.assertEqual(config.extra_path, user_rules_path)
- self.assertEqual(config.get_rule_option(u'my-üser-commit-rule', 'violation-count'), 3)
+ self.assertEqual(config.get_rule_option("my-üser-commit-rule", "violation-count"), 3)
diff --git a/gitlint-core/gitlint/tests/config/test_rule_collection.py b/gitlint-core/gitlint/tests/config/test_rule_collection.py
index 17b50cc..ea7039f 100644
--- a/gitlint-core/gitlint/tests/config/test_rule_collection.py
+++ b/gitlint-core/gitlint/tests/config/test_rule_collection.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
from collections import OrderedDict
from gitlint import rules
from gitlint.config import RuleCollection
@@ -7,7 +5,6 @@ from gitlint.tests.base import BaseTestCase
class RuleCollectionTests(BaseTestCase):
-
def test_add_rule(self):
collection = RuleCollection()
collection.add_rule(rules.TitleMaxLength, "my-rüle", {"my_attr": "föo", "my_attr2": 123})
@@ -29,18 +26,18 @@ class RuleCollectionTests(BaseTestCase):
# find by id
expected = rules.TitleMaxLength()
- rule = collection.find_rule('T1')
+ rule = collection.find_rule("T1")
self.assertEqual(rule, expected)
self.assertEqual(rule.my_attr, "föo")
# find by name
expected2 = rules.TitleTrailingWhitespace()
- rule = collection.find_rule('title-trailing-whitespace')
+ rule = collection.find_rule("title-trailing-whitespace")
self.assertEqual(rule, expected2)
self.assertEqual(rule.my_attr, "föo")
# find non-existing
- rule = collection.find_rule(u'föo')
+ rule = collection.find_rule("föo")
self.assertIsNone(rule)
def test_delete_rules_by_attr(self):