def test_has_length_throws_error_on_notequal_length(value: str, length: int): """ Tests that the `has_length()` method throws an ArgumentError when it is supplied with a not equal length. """ # Arrange validator = StringValidator(value, 'value') # Assert with pytest.raises(ArgumentError): # Act validator.has_length(length)
def test_has_length_accepts_equal_length(value: str, length: int): """ Tests that the `has_length()` method does not throw an ArgumentError when it is supplied with a equal length. """ # Arrange validator = StringValidator(value, 'value') # Act try: validator.has_length(length) # Assert except ArgumentError: pytest.fail(f'`{value}` should have the length `{length}`, but an error occurred.')
def test_has_length_returns_validator_self(): """ Tests if the `has_length()` validator method returns itself after the validation is performed, so that additional validations can be performed. """ # Arrange value = 'test' length = 4 validator = StringValidator(value, 'value') # Act validator_returned = validator.has_length(length) # Assert assert validator_returned is validator