From f3b6c222fb11c96e2f8bbaa0622f46c8ec486874 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 19 Nov 2022 15:52:50 +0100 Subject: Merging upstream version 0.18.0. Signed-off-by: Daniel Baumann --- .../tests/rules/test_configuration_rules.py | 66 ++++++++++++++-------- 1 file changed, 41 insertions(+), 25 deletions(-) (limited to 'gitlint-core/gitlint/tests/rules/test_configuration_rules.py') diff --git a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py index 9302da5..9e3b07c 100644 --- a/gitlint-core/gitlint/tests/rules/test_configuration_rules.py +++ b/gitlint-core/gitlint/tests/rules/test_configuration_rules.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -from gitlint.tests.base import BaseTestCase +from gitlint.tests.base import BaseTestCase, EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING from gitlint import rules from gitlint.config import LintConfig @@ -22,20 +21,25 @@ class ConfigurationRuleTests(BaseTestCase): rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = "DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + \ - "Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: all" - self.assert_log_contains(expected_log_message) + expected_log_messages = [ + EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I1", "ignore-by-title"), + "DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + "Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: all", + ] + self.assert_logged(expected_log_messages) # Matching regex with specific ignore - rule = rules.IgnoreByTitle({"regex": "^Releäse(.*)", - "ignore": "T1,B2"}) + rule = rules.IgnoreByTitle({"regex": "^Releäse(.*)", "ignore": "T1,B2"}) expected_config = LintConfig() expected_config.ignore = "T1,B2" rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = "DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + \ + expected_log_messages += [ + "DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " "Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: T1,B2" + ] + self.assert_logged(expected_log_messages) def test_ignore_by_body(self): commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line") @@ -54,22 +58,26 @@ class ConfigurationRuleTests(BaseTestCase): rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = "DEBUG: gitlint.rules Ignoring commit because of rule 'I2': " + \ - "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)'," + \ - " ignoring rules: all" - self.assert_log_contains(expected_log_message) + expected_log_messages = [ + EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I2", "ignore-by-body"), + "DEBUG: gitlint.rules Ignoring commit because of rule 'I2': " + "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)'," + " ignoring rules: all", + ] + self.assert_logged(expected_log_messages) # Matching regex with specific ignore - rule = rules.IgnoreByBody({"regex": "(.*)relëase(.*)", - "ignore": "T1,B2"}) + rule = rules.IgnoreByBody({"regex": "(.*)relëase(.*)", "ignore": "T1,B2"}) expected_config = LintConfig() expected_config.ignore = "T1,B2" rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = "DEBUG: gitlint.rules Ignoring commit because of rule 'I2': " + \ + expected_log_messages += [ + "DEBUG: gitlint.rules Ignoring commit because of rule 'I2': " "Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)', ignoring rules: T1,B2" - self.assert_log_contains(expected_log_message) + ] + self.assert_logged(expected_log_messages) def test_ignore_by_author_name(self): commit = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line", author_name="Tëst nåme") @@ -88,10 +96,13 @@ class ConfigurationRuleTests(BaseTestCase): rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = ("DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " - "Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)'," - " ignoring rules: all") - self.assert_log_contains(expected_log_message) + expected_log_messages = [ + EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I4", "ignore-by-author-name"), + "DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " + "Commit Author Name 'Tëst nåme' matches the regex '(.*)ëst(.*)'," + " ignoring rules: all", + ] + self.assert_logged(expected_log_messages) # Matching regex with specific ignore rule = rules.IgnoreByAuthorName({"regex": "(.*)nåme", "ignore": "T1,B2"}) @@ -100,9 +111,11 @@ class ConfigurationRuleTests(BaseTestCase): rule.apply(config, commit) self.assertEqual(config, expected_config) - expected_log_message = ("DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " - "Commit Author Name 'Tëst nåme' matches the regex '(.*)nåme', ignoring rules: T1,B2") - self.assert_log_contains(expected_log_message) + expected_log_messages += [ + "DEBUG: gitlint.rules Ignoring commit because of rule 'I4': " + "Commit Author Name 'Tëst nåme' matches the regex '(.*)nåme', ignoring rules: T1,B2" + ] + self.assert_logged(expected_log_messages) def test_ignore_body_lines(self): commit1 = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line") @@ -128,8 +141,11 @@ class ConfigurationRuleTests(BaseTestCase): expected_commit.message.original = commit1.message.original self.assertEqual(commit1, expected_commit) self.assertEqual(config, LintConfig()) # config shouldn't have been modified - self.assert_log_contains("DEBUG: gitlint.rules Ignoring line ' a relëase body' because it " + - "matches '(.*)relëase(.*)'") + expected_log_messages = [ + EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("I3", "ignore-body-lines"), + "DEBUG: gitlint.rules Ignoring line ' a relëase body' because it " + "matches '(.*)relëase(.*)'", + ] + self.assert_logged(expected_log_messages) # Non-Matching regex: no changes expected commit1 = self.gitcommit("Tïtle\n\nThis is\n a relëase body\n line") -- cgit v1.2.3