def test_intg_ensr_is_not_null_throws_error_on_null_value():
    """
    Tests the `is_not_null()` ensures validator method through `Condition.ensures_obj()` to see if it,
	throws an ArgumentNullError when it is supplied with a type that is None (Null).
    """
    # Arrange
    type = None

    # Assert
    with pytest.raises(ArgumentNullError):
        # Act
        Condition.ensures_obj(type, 'type').is_not_null()
def test_intg_ensr_is_not_of_type_name_throws_error_on_no_supplied_initialized_object():
    """
    Tests the `is_not_of_type_name()` ensures validator method through `Condition.ensures_obj()` to see if it,
	throws a TypeError when it is supplied with a type that is not initialized.
    """
    # Arrange
    obj = TypeExample()

    # Assert
    with pytest.raises(TypeError):
        # Act
        Condition.ensures_obj(obj, 'obj').is_not_of_type_name(TypeExample2)
def test_intg_ensr_is_not_of_type_name_throws_error_on_the_same_type():
    """
    Tests the `is_not_of_type_name()` ensures validator method through `Condition.ensures_obj()` to see if it,
	throws an ArgumentError when it is supplied with a type that is the same type instance.
    """
    # Arrange
    type_name = type('type', (object,), {})()

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_obj(type, 'actual').is_not_of_type_name(type_name)
def test_intg_ensr_is_not_equal_throws_error_on_identical_object():
    """
    Tests the `is_not_equal_to()` ensures validator method through `Condition.ensures_obj()` to see if it,
	throws an ArgumentError when the object is identical to the supplied object.
    """
    # Arrange
    actual = TypeExample()
    expected = TypeExample()

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_obj(actual, 'actual').is_not_equal_to(expected)
def test_intg_ensr_is_not_of_type_throws_error_on_equivalent_type():
    """
    Tests the `is_not_of_type()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentError when it is supplied with a type that is the same as the
    specified class type.
    """
    # Arrange
    obj = TypeExample()

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_obj(obj, 'obj').is_not_of_type(TypeExample)
def test_is_intg_ensr_not_of_type_skips_check_if_value_is_none():
    """
    Tests the `is_not_of_type()` ensures validator method skips the type check if the specified value is `None`.
    """
    # Arrange
    obj = None

    # Act
    try:
        Condition.ensures_obj(obj, 'obj').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_intg_ensr_is_of_type_name_skips_check_if_value_is_none():
    """
    Tests the `is_of_type_name()` ensures validator method skips the type check if the specified value is `None`.
    """
    # Arrange
    actual = None
    expected = type('type', (object,), {})()

    # Act
    try:
        Condition.ensures_obj(actual, 'actual').is_of_type_name(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{actual.__class__.__name__}` should match type `{expected.__class__.__name__}`, but an error occurred.')
def test_intg_ensr_is_not_of_type_throws_error_on_no_supplied_type_class():
    """
    Tests the `is_not_of_type()` ensures validator method through `Condition.ensures_obj()` to see if it,
    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,), {})()

    # Assert
    with pytest.raises(TypeError):
        # Act
        Condition.ensures_obj(actual, 'actual').is_not_of_type(expected)
def test_intg_ensr_is_not_of_type_accepts_different_multi_types():
    """
    Tests the `is_not_of_type()` ensures validator method does not throw an ArgumentError
    when it is supplied with multiple types that are all different from the specified class type.
    """
    # Arrange
    obj = TypeExample()

    # Act
    try:
        Condition.ensures_obj(obj, 'obj').is_not_of_type(TypeExample2, TypeExample3)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{obj.__class__.__name__}` should match type `{TypeExample.__name__}`, but an error occurred.')
def test_intg_ensr_is_not_equal_using_ne_should_throw_on_equal_objects():
    """
    Tests the `is_not_equal_to_using_ne()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentError when the object is equal to the supplied object using the
    `__ne__()` validator method.
    """
    # Arrange
    actual = TypeEqualityExample(10)
    expected = TypeEqualityExample(10)

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_obj(actual, 'actual').is_not_equal_to_using_ne(expected)
def test_intg_ensr_is_of_type_name_throws_error_on_different_type():
    """
    Tests the `is_of_type_name()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentError when it is supplied with a type that is not of the
    specified type.
    """
    # Arrange
    actual = type('actual', (object,), {})()
    expected = type('expected', (object,), {})()

    # Assert
    with pytest.raises(ArgumentError):
        # Act
        Condition.ensures_obj(actual, 'actual').is_of_type_name(expected)
def test_intg_ensr_is_not_of_type_accepts_different_type():
    """
    Tests the `is_not_of_type()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentError when it is supplied with a type that is different to the
    specified class type.
    """
    # Arrange
    obj = TypeExample()

    # Act
    try:
        Condition.ensures_obj(obj, 'obj').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_intg_ensr_is_not_equal_to_accepts_non_identical_object_class():
    """
    Tests the `is_not_equal_to()` ensures validator method through `Condition.ensures_obj()` to see if it,
	throws an ArgumentError when the object is not identical to the supplied object.
    """
    # Arrange
    actual = TypeExample()
    expected = TypeExample2()

    # Act
    try:
        Condition.ensures_obj(actual, 'actual').is_not_equal_to(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'`{actual.__class__.__name__}` should be not equal to `{expected.__class__.__name__}`, but an error occurred')
def test_intg_ensr_is_not_null_accepts_not_null_value():
    """
    Tests the `is_not_null()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentNullError when it is supplied with a type that is not None
    (Null).
    """
    # Arrange
    type = TypeExample()

    # Act
    try:
        Condition.ensures_obj(type, 'type').is_not_null()
    # Assert
    except ArgumentNullError:
        pytest.fail(f'The object should have been None (Null), but an error occurred.')
def test_intg_ensr_is_of_type_name_accepts_the_same_type():
    """
    Tests the `is_of_type_name()` ensures validator method through `Condition.ensures_obj()` to see if it,
    does not throw an ArgumentError when it is supplied with a type that is the same
    type instance.
    """
    # Arrange
    type_name = type('type', (object,), {})()

    # Act
    try:
        Condition.ensures_obj(type, 'actual').is_of_type_name(type_name)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{type_name.__class__.__name__}` should match type `{type_name.__class__.__name__}`, but an error occurred.')
def test_intg_ensr_is_of_type_name_accepts_equivalent_type():
    """
    Tests the `is_of_type_name()` ensures validator method through `Condition.ensures_obj()` to see if it,
    does not throw an ArgumentError when it is supplied with a type that is of the specified type.
    """
    # Arrange
    actual = type('type', (object,), {})()
    expected = type('type', (object,), {})()

    # Act
    try:
        Condition.ensures_obj(actual, 'actual').is_of_type_name(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{actual.__class__.__name__}` should match type `{expected.__class__.__name__}`, but an error occurred.')
def test_intg_ensr_is_not_of_type_name_accepts_different_multi_types():
    """
    Tests the `is_not_of_type_name()` ensures validator method does not throw an ArgumentError
    when it is supplied with a multiple types that are all not the same as the supplied type.
    """
    # Arrange
    actual = type('actual', (object,), {})()
    expected = type('expected', (object,), {})()
    expected2 = type('expected2', (object,), {})()

    # Act
    try:
        Condition.ensures_obj(actual, 'actual').is_not_of_type_name(expected, expected2)
    # Assert
    except ArgumentError:
        pytest.fail(f'Type `{actual.__class__.__name__}` should match type `{expected.__class__.__name__}`, but an error occurred.')
def test_intg_ensr_is_not_equal_using_ne_accepts_unequal_objects():
    """
    Tests the `is_not_equal_to_using_eq()` ensures validator method through `Condition.ensures_obj()` to see if it,
    throws an ArgumentError when the object is not equal to the supplied object using the
    `__ne__()` validator method.
    """
    # Arrange
    actual = TypeEqualityExample(10)
    expected = TypeEqualityExample(11)

    # Act
    try:
        Condition.ensures_obj(actual, 'actual').is_not_equal_to_using_ne(expected)
    # Assert
    except ArgumentError:
        pytest.fail(f'`{actual.__class__.__name__}` should be equal to `{expected.__class__.__name__}` when using the `__eq__()` function, but an error occurred')
Exemplo n.º 19
0
def test_ensures_returns_object_validator():
    """
    Tests if the `Condition.ensures()` method returns the validator that is appropriate to
    the object datatype.
    """
    # Arrange
    obj = TypeExample()

    # Act
    validator = Condition.ensures_obj(obj, 'obj')

    # Assert
    assert isinstance(validator, ObjectValidator)
def test_intg_ensr_prnt_get_value_returns_value():
    """
    Tests if the parent `get_value()` ensures validator method returns the value saved in the validator.
    """
    # Arrange
    obj = type('type', (object,), {})()

    # Act
    actual = Condition.ensures_obj(obj, 'obj').get_value()

    # Assert
    assert actual == obj
    assert actual is obj
    assert type(actual) == type(obj)