diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-03-19 14:00:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2020-03-19 14:00:14 +0000 |
commit | df9615bac55ac6f1c3f516b66279ac0007175030 (patch) | |
tree | 84dd81d1c97835271cea7fbdd67c074742365e07 /gitlint/tests/rules/test_configuration_rules.py | |
parent | Initial commit. (diff) | |
download | gitlint-df9615bac55ac6f1c3f516b66279ac0007175030.tar.xz gitlint-df9615bac55ac6f1c3f516b66279ac0007175030.zip |
Adding upstream version 0.13.1.upstream/0.13.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gitlint/tests/rules/test_configuration_rules.py')
-rw-r--r-- | gitlint/tests/rules/test_configuration_rules.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/gitlint/tests/rules/test_configuration_rules.py b/gitlint/tests/rules/test_configuration_rules.py new file mode 100644 index 0000000..73d42f3 --- /dev/null +++ b/gitlint/tests/rules/test_configuration_rules.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +from gitlint.tests.base import BaseTestCase +from gitlint import rules +from gitlint.config import LintConfig + + +class ConfigurationRuleTests(BaseTestCase): + def test_ignore_by_title(self): + commit = self.gitcommit(u"Releäse\n\nThis is the secōnd body line") + + # No regex specified -> Config shouldn't be changed + rule = rules.IgnoreByTitle() + config = LintConfig() + rule.apply(config, commit) + self.assertEqual(config, LintConfig()) + self.assert_logged([]) # nothing logged -> nothing ignored + + # Matching regex -> expect config to ignore all rules + rule = rules.IgnoreByTitle({"regex": u"^Releäse(.*)"}) + expected_config = LintConfig() + expected_config.ignore = "all" + rule.apply(config, commit) + self.assertEqual(config, expected_config) + + expected_log_message = u"DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + \ + u"Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: all" + self.assert_log_contains(expected_log_message) + + # Matching regex with specific ignore + rule = rules.IgnoreByTitle({"regex": u"^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 = u"DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + \ + u"Commit title 'Releäse' matches the regex '^Releäse(.*)', ignoring rules: T1,B2" + + def test_ignore_by_body(self): + commit = self.gitcommit(u"Tïtle\n\nThis is\n a relëase body\n line") + + # No regex specified -> Config shouldn't be changed + rule = rules.IgnoreByBody() + config = LintConfig() + rule.apply(config, commit) + self.assertEqual(config, LintConfig()) + self.assert_logged([]) # nothing logged -> nothing ignored + + # Matching regex -> expect config to ignore all rules + rule = rules.IgnoreByBody({"regex": u"(.*)relëase(.*)"}) + expected_config = LintConfig() + expected_config.ignore = "all" + rule.apply(config, commit) + self.assertEqual(config, expected_config) + + expected_log_message = u"DEBUG: gitlint.rules Ignoring commit because of rule 'I2': " + \ + u"Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)'," + \ + u" ignoring rules: all" + self.assert_log_contains(expected_log_message) + + # Matching regex with specific ignore + rule = rules.IgnoreByBody({"regex": u"(.*)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 = u"DEBUG: gitlint.rules Ignoring commit because of rule 'I1': " + \ + u"Commit message line ' a relëase body' matches the regex '(.*)relëase(.*)', ignoring rules: T1,B2" |