def test_is_not_of_type_throws_error_on_equivalent_type(): """ Tests that the `is_not_of_type()` method throws an ArgumentError when it is supplied with a type that is the same as the specified class type. """ # Arrange obj = TypeExample() validator = ObjectValidator(obj, 'obj') # Assert with pytest.raises(ArgumentError): # Act validator.is_not_of_type(TypeExample)
def test_is_not_of_type_throws_error_on_no_supplied_type_class(): """ Tests that the `is_not_of_type()` method throws a TypeError when it is supplied with a type that is initialized rather than a class type. """ # Arrange actual = type('actual', (object,), {})() expected = type('expected', (object,), {})() validator = ObjectValidator(actual, 'actual') # Assert with pytest.raises(TypeError): # Act validator.is_not_of_type(expected)
def test_is_not_of_type_skips_check_if_value_is_none(): """ Tests that the `is_not_of_type()` skips the type check if the specified value is `None`. """ # Arrange obj = None validator = ObjectValidator(obj, 'obj') # Act try: validator.is_not_of_type(TypeExample2) # Assert except ArgumentError: pytest.fail(f'Type `{obj.__class__.__name__}` should match type `{TypeExample.__name__}`, but an error occurred.')
def test_is_not_of_type_accepts_different_type(): """ Tests that the `is_not_of_type()` method does not throw an ArgumentError when it is supplied with a type that is different to the specified class type. """ # Arrange obj = TypeExample() validator = ObjectValidator(obj, 'obj') # Act try: validator.is_not_of_type(TypeExample2) # Assert except ArgumentError: pytest.fail(f'Type `{obj.__class__.__name__}` should match type `{TypeExample.__name__}`, but an error occurred.')
def test_is_not_of_type_returns_validator_self(): """ Tests if the `is_not_of_type()` validator method returns itself after the validation is performed, so that additional validations can be performed. """ # Arrange obj = TypeExample() validator = ObjectValidator(obj, 'obj') # Act validator_returned = validator.is_not_of_type(TypeExample2) # Assert assert validator_returned is validator