コード例 #1
0
def test_not_raise() -> None:
    """Must not raise when ``val`` is instance of ``val_type``."""
    for val in [
            False, True, 0, 1, -1, 0.1, -0.1, '', None, (), [], {},
            set(), ..., NotImplemented
    ]:
        raise_if_not_instance(val=val, val_name='test', val_type=type(val))
コード例 #2
0
def test_raise_if_not_bool() -> None:
    """Must raise :py:class:`TypeError` when ``val`` is not instance of :py:class:`bool`."""
    for not_bool in [
            0, 1, -1, 0.1, -0.1, '', None, (), [], {},
            set(), ..., NotImplemented
    ]:
        with pytest.raises(TypeError) as excinfo:
            raise_if_not_instance(val=not_bool, val_name='test', val_type=bool)

        assert '`test` must be an instance of `bool`.' in str(excinfo.value)