From 3313b4f9c3c5d6a579588e77068ca3ae3edffe2b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 25 Jan 2021 14:26:08 +0100 Subject: Adding upstream version 0.15.0. Signed-off-by: Daniel Baumann --- gitlint/tests/config/test_config.py | 69 +++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 37 deletions(-) (limited to 'gitlint/tests/config/test_config.py') 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)), "") + self.assertEqual(str(type(actual_rule)), "") 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)), "") + self.assertEqual(str(type(actual_rule)), "") 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)), "") + self.assertEqual(str(type(actual_rule)), "") 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") -- cgit v1.2.3