def test_intg_ensr_is_null_throws_error_on_invalid_value(value: str):
    """
    Tests the `is_null()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with an invalid value.
    """
    # Assert
    with pytest.raises(ArgumentNullError):
        # Act
        Condition.ensures_str(value, 'value').is_null()
def test_intg_ensr_does_not_contain_throw_error_on_invalid_value(
        value: str, contains: str):
    """
    Tests the `does_not_contain()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when the value contains specified value.
    """
    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').does_not_contain(contains)
def test_intg_ensr_does_not_have_length_throws_error_on_equal_length(
        value: str, length: int):
    """
    Tests the `does_not_have_length()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a equal length.
    """
    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').does_not_have_length(length)
def test_intg_ensr_does_not_end_with_throws_error_on_invalid_value(
        value: str, ends_with: str):
    """
    Tests the `does_not_end_with()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when the value ends with the specified value.
    """
    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').does_not_end_with(ends_with)
def test_intg_ensr_is_not_regex_match_throws_error_on_matching_pattern(
        value: str, pattern: str):
    """
    Tests the `is_not_regex_match()` ensures validator method through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when the value matches the specified pattern.
    """
    # Assert
    with pytest.raises(ArgumentPatternError):
        # Act
        Condition.ensures_str(value, 'value').is_not_regex_match(pattern)
def test_intg_ensr_is_longer_or_equal_throws_error_on_shorter_length(
        value: str, min_length: int):
    """
    Tests the `is_longer_or_equal()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a shorter length.
    """
    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').is_longer_or_equal(min_length)
def test_intg_ensr_is_null_or_empty_throws_error_on_whitespace_value():
    """
    Tests the `is_null_or_empty()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a whitespace value.
    """
    # Arrange
    value = WHITESPACE_STRING

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').is_null_or_empty()
def test_intg_ensr_is_not_null_or_whitespace_throw_error_on_null_value():
    """
    Tests the `is_not_null_or_whitespace()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a None (Null) value.
    """
    # Arrange
    value = None

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').is_not_null_or_whitespace()
def test_intg_ensr_contains_accepts_valid_value(value: str, contains: str):
    """
    Tests the `contains()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when the value does contains specified value.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').contains(contains)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should contain `{contains}`, but an error occurred.')
def test_intg_ensr_ends_with_accepts_valid_value(value: str, ends_with: str):
    """
    Tests the `ends_with()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when the value ends with the specified value.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').ends_with(ends_with)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should end with `{ends_with}`, but an error occurred.')
def test_intg_ensr_does_not_equal_throws_error_on_equal_value():
    """
    Tests the `equals()` ensures validator method throws an ArgumentError
    when the value is not equal to the specified value.
    """
    # Arrange
    value = 'Hello World!'

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_str(value, 'value').does_not_equal(value)
def test_intg_ensr_is_null_throws_error_on_empty_value():
    """
    Tests the `is_null()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with an empty value.
    """
    # Arrange
    value = EMPTY_STRING

    # Assert
    with pytest.raises(ArgumentNullError):
        # Act
        Condition.ensures_str(value, 'value').is_null()
def test_intg_ensr_is_not_null_accepts_valid_value(value: str):
    """
    Tests the `is_not_null()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a valid value.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').is_not_null()
    # Assert
    except ArgumentNullError:
        pytest.fail(
            f'`{value}` should not have been None (Null), but an error occurred instead.'
        )
def test_intg_ensr_has_length_accepts_equal_length(value: str, length: int):
    """
    Tests the `has_length()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when it is supplied with a equal length.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').has_length(length)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should have the length `{length}`, but an error occurred.'
        )
def test_intg_ensr_is_not_null_or_whitespace_accepts_valid_value(value: str):
    """
    Tests the `is_not_null_or_whitespace()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when it is supplied with a valid value.
    """
    # Assert
    try:
        Condition.ensures_str(value, 'value').is_not_null_or_whitespace()
    # Assert
    except (ArgumentError, ArgumentNullError):
        pytest.fail(
            f'`{value}` should not have been None (Null) or empty, but an error occurred instead.'
        )
def test_intg_ensr_is_longer_or_equal_accepts_equal_length(
        value: str, min_length: int):
    """
    Tests the `is_longer_or_equal()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when it is supplied with a equal length.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').is_longer_or_equal(min_length)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should be longer or equal to `{min_length}`, but an error occurred.'
        )
def test_intg_ensr_equals_accepts_equal_value():
    """
    Tests the `equals()` ensures validator method does not throw an ArgumentError
    when the value is equal to the specified value.
    """
    # Arrange
    value = 'Hello World!'

    # Act
    try:
        Condition.ensures_str(value, 'value').equals(value)
    # Assert
    except ArgumentError:
        pytest.fail()
def test_intg_ensr_is_not_regex_match_accepts_not_matching_pattern(
        value: str, pattern: str):
    """
    Tests the `is_not_regex_match()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when the value does not match the specified pattern.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').is_not_regex_match(pattern)
    # Assert
    except ArgumentPatternError:
        pytest.fail(
            f'`{value}` should match the pattern `{pattern}`, but an error occurred.'
        )
def test_intg_ensr_is_shorter_than_accepts_shorter_length(
        value: str, max_length: int):
    """
    Tests the `is_shorter_than()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when it is supplied with a shorter length.
    """
    # Act
    try:
        Condition.ensures_str(value, 'value').is_shorter_than(max_length)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should be shorter than `{max_length}`, but an error occurred.'
        )
def test_intg_ensr_is_null_or_empty_accepts_empty_value():
    """
    Tests the `is_null_or_empty()` through `Condition.ensures_str()` to see if it,
    throws an ArgumentError when it is supplied with a empty value.
    """
    # Arrange
    value = EMPTY_STRING

    # Act
    try:
        Condition.ensures_str(value, 'value').is_null_or_empty()
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should have been None (Null) or empty, but an error occurred instead.'
        )
def test_intg_ensr_is_null_or_whitespace_accepts_whitespace_value():
    """
    Tests the `is_not_null_or_whitespace()` through `Condition.ensures_str()` to see if it,
    does not throw an ArgumentError when it is supplied with a whitespace value.
    """
    # Arrange
    value = WHITESPACE_STRING

    # Act
    try:
        Condition.ensures_str(value, 'value').is_null_or_whitespace()
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should have been None (Null), empty or whitespace, but an error occurred instead.'
        )
Exemplo n.º 22
0
def test_ensures_returns_string_validator(value: str):
    """
    Tests if the `Condition.ensures_str()` method returns the validator that is appropriate to
    the string datatype.
    """
    # Act
    validator = Condition.ensures_str(value, 'value')

    # Assert
    assert isinstance(validator, StringValidator)
def test_intg_ensr_prnt_get_value_returns_value(value):
    """
    Tests if the parent `get_value()` ensures validator method returns the value saved in the validator.
    """
    # Act
    actual = Condition.ensures_str(value, 'value').get_value()

    # Assert
    assert actual == value
    assert actual is value
    assert type(actual) == type(value)
def test_intg_ensr_is_not_in_set_case_insensitive_throws_error_on_matching_set(
        value: str, set: list):
    """
    Tests the `is_not_in_set_case_insensitive()` ensures validator method throws an ArgumentError when its value is present
    in the supplied set, case insensitive.
    """
    # Arrange
    validator = Condition.ensures_str(value, 'value')

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        validator.is_not_in_set_case_insensitive(set)
def test_intg_ensr_is_in_set_accepts_value_in_set(value: str, set: list):
    """
    Tests the `is_in_set()` ensures validator method does not throw an ArgumentError when its value is present
    in the supplied set.
    """
    # Arrange
    validator = Condition.ensures_str(value, 'value')

    # Act
    try:
        validator.is_in_set(set)
    # Assert
    except ArgumentError:
        pytest.fail(
            f'`{value}` should be in the set `{set}`, but an error occurred.')