Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flunt/localization/flunt_regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
}


def get_pattern(name: str) -> str | Pattern[str]:
def get_pattern(name: str) -> str | Pattern[str] | None:
"""Retrieve a regex pattern by its name."""
value = REGEX_PATTERNS.get(name)
if value is None:
return ""
return None
return value
4 changes: 2 additions & 2 deletions flunt/validations/bool_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def is_false(

"""
if self.__to_bool(value):
if message is IS_FALSE:
if message == IS_FALSE:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -116,7 +116,7 @@ def is_true(

"""
if not self.__to_bool(value):
if message is IS_TRUE:
if message == IS_TRUE:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
4 changes: 2 additions & 2 deletions flunt/validations/brazilian_document_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def is_cpf(

"""
if not _validate_cpf(value):
if message is IS_NOT_CPF:
if message == IS_NOT_CPF:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -230,7 +230,7 @@ def is_cnpj(

"""
if not _validate_cnpj(value):
if message is IS_NOT_CNPJ:
if message == IS_NOT_CNPJ:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
10 changes: 5 additions & 5 deletions flunt/validations/collections_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_lower_than(
return self

if len(value) >= comparer:
if message is LOWER_THAN:
if message == LOWER_THAN:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -118,7 +118,7 @@ def is_lower_or_equals_than(
return self

if len(value) > comparer:
if message is LOWER_OR_EQUALS_THAN:
if message == LOWER_OR_EQUALS_THAN:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -165,7 +165,7 @@ def is_greater_than(
return self

if len(value) <= comparer:
if message is GREATER_THAN:
if message == GREATER_THAN:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -212,7 +212,7 @@ def is_greater_or_equals_than(
return self

if len(value) < comparer:
if message is GREATER_OR_EQUALS_THAN:
if message == GREATER_OR_EQUALS_THAN:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -267,7 +267,7 @@ def is_between(
return self

if not min <= len(value) <= max:
if message is IS_BETWEEN:
if message == IS_BETWEEN:
self.add_notification(field, message.format(field, min, max))
return self
self.add_notification(field, message)
Expand Down
8 changes: 4 additions & 4 deletions flunt/validations/commons_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def is_none(self, value: T, field: str, message: str = IS_NONE) -> Self:

"""
if value is not None:
if message is IS_NONE:
if message == IS_NONE:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -77,7 +77,7 @@ def is_not_none(

"""
if value is None:
if message is REQUIRED:
if message == REQUIRED:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -112,7 +112,7 @@ def are_equals(

"""
if value != comparer:
if message is EQUALS:
if message == EQUALS:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -147,7 +147,7 @@ def are_not_equals(

"""
if value == comparer:
if message is NOT_EQUALS:
if message == NOT_EQUALS:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down
2 changes: 1 addition & 1 deletion flunt/validations/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def requires(

"""
if not value and not isinstance(value, bool | int | float):
if message is REQUIRED:
if message == REQUIRED:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
4 changes: 2 additions & 2 deletions flunt/validations/credit_card_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def is_credit_card(

pattern = _get_only_numbers_pattern()
if pattern is None or not pattern.match(value):
if message is IS_NOT_CREDIT_CARD:
if message == IS_NOT_CREDIT_CARD:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
return self

if not _luhn_checksum(value):
if message is IS_NOT_CREDIT_CARD:
if message == IS_NOT_CREDIT_CARD:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
4 changes: 2 additions & 2 deletions flunt/validations/email_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def is_email(

"""
if not _valid_email(value):
if message is IS_EMAIL:
if message == IS_EMAIL:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -126,7 +126,7 @@ def is_not_email(

"""
if _valid_email(value):
if message is IS_NOT_EMAIL:
if message == IS_NOT_EMAIL:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
6 changes: 3 additions & 3 deletions flunt/validations/strings_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def is_not_none_or_white_space(

"""
if value is None or not str(value).strip():
if message is IS_NOT_NONE_OR_WHITESPACE:
if message == IS_NOT_NONE_OR_WHITESPACE:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -86,7 +86,7 @@ def contains(

"""
if not isinstance(value, str) or comparer not in value:
if message is CONTAINS:
if message == CONTAINS:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -120,7 +120,7 @@ def not_contains(

"""
if not isinstance(value, str) or comparer in value:
if message is NOT_CONTAINS:
if message == NOT_CONTAINS:
self.add_notification(field, message.format(field, comparer))
return self
self.add_notification(field, message)
Expand Down
4 changes: 2 additions & 2 deletions flunt/validations/url_validation_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def is_url(

"""
if not _valid_url(value):
if message is IS_URL:
if message == IS_URL:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down Expand Up @@ -122,7 +122,7 @@ def is_not_url(

"""
if _valid_url(value):
if message is IS_NOT_URL:
if message == IS_NOT_URL:
self.add_notification(field, message.format(field))
return self
self.add_notification(field, message)
Expand Down
6 changes: 6 additions & 0 deletions tests/localization/test_flunt_regex_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def test_should_identify_letters_and_numbers(value: str, expect: bool) -> None:
assert isinstance(result, re.Match) is expect


def test_should_return_none_for_unknown_pattern() -> None:
"""Test that get_pattern returns None for an unknown pattern name."""
result = get_pattern("non_existent_pattern")
assert result is None


@pytest.mark.parametrize(
("value", "expect"),
[
Expand Down