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

    assert is_instance(value, var) == expected
예제 #12
0
def test_typevar(value, constraints, expected):
    var = TypeVar('T', *constraints)

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