Exemple #1
0
def test_is_not_of_type_name_throws_error_on_no_supplied_initialized_object():
    """
    Tests that the `is_not_of_type_name()` method throws a TypeError
    when it is supplied with a type that is not initialized.
    """
    # Arrange
    obj = TypeExample()
    validator = ObjectValidator(obj, 'obj')

    # Assert
    with pytest.raises(TypeError):
        # Act
        validator.is_not_of_type_name(TypeExample2)
Exemple #2
0
def test_is_not_of_type_name_throws_error_on_the_same_type():
    """
    Tests that the `is_not_of_type_name()` method throws an ArgumentError
    when it is supplied with a type that is the same type instance.
    """
    # Arrange
    type_name = type('type', (object,), {})()
    validator = ObjectValidator(type, 'actual')

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        validator.is_not_of_type_name(type_name)
Exemple #3
0
def test_is_not_of_type_name_throws_error_on_equivalent_type():
    """
    Tests that the `is_not_of_type_name()` method throws an ArgumentError
    when it is supplied with a type that is equivalent to the specified type.
    """
    # Arrange
    actual = type('type', (object,), {})()
    expected = type('type', (object,), {})()
    validator = ObjectValidator(actual, 'actual')

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        validator.is_not_of_type_name(expected)
Exemple #4
0
def test_is_not_of_type_name_skips_check_if_value_is_none():
    """
    Tests that the `is_not_of_type_name()` skips the type check if the specified value is `None`.
    """
    # Arrange
    actual = None
    expected = type('expected', (object,), {})()
    validator = ObjectValidator(actual, 'actual')

    # Act
    try:
        validator.is_not_of_type_name(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{actual.__class__.__name__}` should match type `{expected.__class__.__name__}`, but an error occurred.')
Exemple #5
0
def test_is_not_of_type_name_accepts_different_type():
    """
    Tests that the `is_not_of_type_name()` method does not throw an ArgumentError
    when it is supplied with a type that is not the same as the supplied type.
    """
    # Arrange
    actual = type('actual', (object,), {})()
    expected = type('expected', (object,), {})()
    validator = ObjectValidator(actual, 'actual')

    # Act
    try:
        validator.is_not_of_type_name(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{actual.__class__.__name__}` should match type `{expected.__class__.__name__}`, but an error occurred.')
Exemple #6
0
def test_is_not_of_type_name_returns_validator_self():
    """
    Tests if the `is_not_of_type_name()` validator method returns itself after the validation is performed,
    so that additional validations can be performed.
    """
    # Arrange
    actual = type('actual', (object,), {})()
    expected = type('expected', (object,), {})()
    validator = ObjectValidator(actual, 'actual')

    # Act
    validator_returned = validator.is_not_of_type_name(expected)

    # Assert
    assert validator_returned is validator