Exemplo n.º 1
0
def is_not_whitespace(
    value: str, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if len(value.strip()) <= 0:
        raise ArgumentError(
            TextErrorMessages.is_not_whitespace_message(argument_name), argument_name
        ) if exception is None else exception
Exemplo n.º 2
0
def is_uppercase(
    value: str, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if not value.isupper():
        raise ArgumentError(
            TextErrorMessages.is_uppercase_message(argument_name, value), argument_name
        ) if exception is None else exception
Exemplo n.º 3
0
def is_alphabetic(
    value: str, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if not value.isalpha():
        raise ArgumentError(
            TextErrorMessages.is_alphabetic_message(argument_name, value), argument_name
        ) if exception is None else exception
Exemplo n.º 4
0
def is_not_empty(list: List,
                 argument_name: str = None,
                 exception: Exception = None) -> None:
    """ Check if the given list is not empty """
    NoneType.is_not_none(list, argument_name, exception)
    if not list:
        raise ArgumentError(
            ListErrorMessages.is_not_empty_message(argument_name),
            argument_name) if exception is None else exception
Exemplo n.º 5
0
def has_length(
    value: str, length: int, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if len(value) != length:
        raise ArgumentError(
            TextErrorMessages.has_length_message(argument_name, len(value), length),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 6
0
def is_not_equal_to(
    value: str, expected: str, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if value == expected:
        raise ArgumentError(
            TextErrorMessages.is_not_equal_to_message(argument_name, value),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 7
0
def contains(list: List,
             element: T,
             argument_name: str = None,
             exception: Exception = None) -> None:
    """ Check if a given element is present in the list """
    NoneType.is_not_none(list, argument_name, exception)
    if element not in list:
        raise ArgumentError(
            ListErrorMessages.contains_message(argument_name, element),
            argument_name) if exception is None else exception
Exemplo n.º 8
0
def has_no_repeated_elements(list: List,
                             argument_name: str = None,
                             exception: Exception = None) -> None:
    """ Check if the list has not repeated values """
    NoneType.is_not_none(list, argument_name, exception)
    if len(list) != len(set(list)):
        raise ArgumentError(
            ListErrorMessages.has_not_repeated_elements_message(argument_name),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 9
0
def is_integer(
    value: str, argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    try:
        int(value)
    except Exception:
        raise ArgumentError(
            TextErrorMessages.is_integer_message(argument_name, value), argument_name
        ) if exception is None else exception
Exemplo n.º 10
0
def is_not_empty(
    value: Union[str, List], argument_name: str = None, exception: Exception = None
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    if isinstance(value, str):
        value = value.strip()
    if len(value) <= 0:
        raise ArgumentError(
            TextErrorMessages.is_not_empty_message(argument_name), argument_name
        ) if exception is None else exception
Exemplo n.º 11
0
def has_all_elements_of_same_type(list: List,
                                  argument_name: str = None,
                                  exception: Exception = None) -> None:
    """ Check if the elements' list are all of the same type """
    NoneType.is_not_none(list, argument_name, exception)

    if len(set(map(type, list))) != 1:
        raise ArgumentError(
            ListErrorMessages.all_elements_of_same_type_message(argument_name),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 12
0
def is_length_equals(
    list: List,
    condition_value: int,
    argument_name: str = None,
    exception: Exception = None,
) -> None:
    """ Check if the given list length is equals than the condition_value """
    NoneType.is_not_none(list, argument_name, exception)
    if len(list) != condition_value:
        raise ArgumentError(
            ListErrorMessages.has_length_equals_message(
                argument_name, condition_value),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 13
0
def has_all_elements_of_type(
    list: List,
    expected_type: type,
    argument_name: str = None,
    exception: Exception = None,
) -> None:
    """ Check if the elements' list are all of a given type """
    NoneType.is_not_none(list, argument_name, exception)
    if any(type(element) != expected_type for element in list):
        raise ArgumentError(
            ListErrorMessages.all_elements_of_type_message(
                argument_name, expected_type),
            argument_name,
        ) if exception is None else exception
Exemplo n.º 14
0
def has_length_between(
    value: str,
    min_lenght: int,
    max_lenght: int,
    argument_name: str = None,
    exception: Exception = None,
) -> None:
    NoneType.is_not_none(value, argument_name, exception)
    value_length = len(value)
    if value_length < min_lenght or value_length > max_lenght:
        raise ArgumentError(
            TextErrorMessages.has_length_between_message(
                argument_name, len(value), min_lenght, max_lenght
            ),
            argument_name,
        ) if exception is None else exception