def test_basic_type():
    assert is_instance(5, int)
def test_ellipsis():
    assert is_instance(..., 'ellipsis')
def test_union(value, type_, expected):
    assert is_instance(value, type_) == expected
def test_nested_generics():
    assert is_instance(([1.5], 'bar'), Tuple[List[float], str])
def test_any():
    assert is_instance(5, Any)
def test_unannotated_callable(value, type_):
    with pytest.raises(ValueError):
        is_instance(value, type_)
def test_tuple():
    assert is_instance(('bar', True), Tuple[str, bool])
def test_generic_iterable_with_mixed_types():
    assert not is_instance([1, 2.5], List[int])
def test_generic_mapping():
    assert is_instance({1: 'foo'}, Dict[int, str])
Esempio n. 10
0
def test_empty_iterable():
    assert is_instance([], List[bool])
Esempio n. 11
0
def test_bounded_typevar(value, bound, expected):
    var = TypeVar('T', bound=bound)

    assert is_instance(value, var) == expected
Esempio n. 12
0
def test_typevar(value, constraints, expected):
    var = TypeVar('T', *constraints)

    assert is_instance(value, var) == expected
Esempio n. 13
0
def test_callable_with_typevars(value, type_, expected):
    assert is_instance(value, type_) == expected
Esempio n. 14
0
def test_generic_iterable():
    assert is_instance([1, 2], List[int])
Esempio n. 15
0
def test_supportsX(value, type_, expected):
    assert is_instance(value, type_) == expected
Esempio n. 16
0
def test_generic_mapping_detects_wrong_value_type():
    assert not is_instance({1: 'foo'}, Dict[int, float])
Esempio n. 17
0
def test_iterable(value, type_, expected):
    assert is_instance(value, type_) == expected
Esempio n. 18
0
def test_typing_type():
    assert is_instance([], List)