summaryrefslogtreecommitdiffstats
path: root/gitlint-core/gitlint/tests/rules/test_meta_rules.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlint-core/gitlint/tests/rules/test_meta_rules.py')
-rw-r--r--gitlint-core/gitlint/tests/rules/test_meta_rules.py48
1 files changed, 33 insertions, 15 deletions
diff --git a/gitlint-core/gitlint/tests/rules/test_meta_rules.py b/gitlint-core/gitlint/tests/rules/test_meta_rules.py
index 568ca3f..0b8a10a 100644
--- a/gitlint-core/gitlint/tests/rules/test_meta_rules.py
+++ b/gitlint-core/gitlint/tests/rules/test_meta_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.rules import AuthorValidEmail, RuleViolation
@@ -8,8 +7,13 @@ class MetaRuleTests(BaseTestCase):
rule = AuthorValidEmail()
# valid email addresses
- valid_email_addresses = ["föo@bar.com", "Jöhn.Doe@bar.com", "jöhn+doe@bar.com", "jöhn/doe@bar.com",
- "jöhn.doe@subdomain.bar.com"]
+ valid_email_addresses = [
+ "föo@bar.com",
+ "Jöhn.Doe@bar.com",
+ "jöhn+doe@bar.com",
+ "jöhn/doe@bar.com",
+ "jöhn.doe@subdomain.bar.com",
+ ]
for email in valid_email_addresses:
commit = self.gitcommit("", author_email=email)
violations = rule.validate(commit)
@@ -22,19 +26,32 @@ class MetaRuleTests(BaseTestCase):
self.assertIsNone(violations)
# Invalid email addresses: no TLD, no domain, no @, space anywhere (=valid but not allowed by gitlint)
- invalid_email_addresses = ["föo@bar", "JöhnDoe", "Jöhn Doe", "Jöhn Doe@foo.com", " JöhnDoe@foo.com",
- "JöhnDoe@ foo.com", "JöhnDoe@foo. com", "JöhnDoe@foo. com", "@bår.com",
- "föo@.com"]
+ invalid_email_addresses = [
+ "föo@bar",
+ "JöhnDoe",
+ "Jöhn Doe",
+ "Jöhn Doe@foo.com",
+ " JöhnDoe@foo.com",
+ "JöhnDoe@ foo.com",
+ "JöhnDoe@foo. com",
+ "JöhnDoe@foo. com",
+ "@bår.com",
+ "föo@.com",
+ ]
for email in invalid_email_addresses:
commit = self.gitcommit("", author_email=email)
violations = rule.validate(commit)
- self.assertListEqual(violations,
- [RuleViolation("M1", "Author email for commit is invalid", email)])
+ self.assertListEqual(violations, [RuleViolation("M1", "Author email for commit is invalid", email)])
+
+ # Ensure nothing is logged, this relates specifically to a deprecation warning on the use of
+ # re.match vs re.search in the rules (see issue #254)
+ # If no custom regex is used, the rule uses the default regex in combination with re.search
+ self.assert_logged([])
def test_author_valid_email_rule_custom_regex(self):
# regex=None -> the rule isn't applied
rule = AuthorValidEmail()
- rule.options['regex'].set(None)
+ rule.options["regex"].set(None)
emailadresses = ["föo", None, "hür dür"]
for email in emailadresses:
commit = self.gitcommit("", author_email=email)
@@ -42,9 +59,8 @@ class MetaRuleTests(BaseTestCase):
self.assertIsNone(violations)
# Custom domain
- rule = AuthorValidEmail({'regex': "[^@]+@bår.com"})
- valid_email_addresses = [
- "föo@bår.com", "Jöhn.Doe@bår.com", "jöhn+doe@bår.com", "jöhn/doe@bår.com"]
+ rule = AuthorValidEmail({"regex": "[^@]+@bår.com"})
+ valid_email_addresses = ["föo@bår.com", "Jöhn.Doe@bår.com", "jöhn+doe@bår.com", "jöhn/doe@bår.com"]
for email in valid_email_addresses:
commit = self.gitcommit("", author_email=email)
violations = rule.validate(commit)
@@ -55,5 +71,7 @@ class MetaRuleTests(BaseTestCase):
for email in invalid_email_addresses:
commit = self.gitcommit("", author_email=email)
violations = rule.validate(commit)
- self.assertListEqual(violations,
- [RuleViolation("M1", "Author email for commit is invalid", email)])
+ self.assertListEqual(violations, [RuleViolation("M1", "Author email for commit is invalid", email)])
+
+ # When a custom regex is used, a warning should be logged by default
+ self.assert_logged([EXPECTED_REGEX_STYLE_SEARCH_DEPRECATION_WARNING.format("M1", "author-valid-email")])