Esempio n. 1
0
def is_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_equal_to_message(argument_name, value, expected),
            argument_name,
        ) if exception is None else exception
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
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