def test_dict():
    _dict = dict()
    _dict_str_int = {"a": 1, "b": 2}
    _dict_int_bool = {0: False, 1: True}
    assert istype(_dict, dict) is True
    assert istype(_dict, tp.Dict) is True
    assert istype(_dict_str_int, tp.Dict[str, int]) is True
    assert istype(_dict_int_bool, tp.Dict[int, bool]) is True
def test_list():
    _list = list()
    _list_of_str = ["str", "str"]
    _list_of_int = [0, 1]
    _list_of_bools = [True, False]
    _list_of_none = [None, None]
    _list_of_lists = [list(), list()]
    _list_recursive = [[1, 2], [3, 4]]
    _list_of_multiple_types = [1, "str", True]

    assert istype(_list, list) is True
    assert istype(_list, tp.List) is True
    assert istype(_list_of_str, tp.List[str]) is True
    assert istype(_list_of_int, tp.List[int]) is True
    assert istype(_list_of_bools, tp.List[bool]) is True
    assert istype(_list_of_none, tp.List[None]) is True
    assert istype(_list_of_lists, tp.List[list]) is True
    assert istype(_list_recursive, tp.List[tp.List[int]]) is True
    assert istype(_list_of_multiple_types, tp.List[int]) is False
def test_lambda():
    _lambda = lambda o: o  # noqa
    assert istype(_lambda, tp.Callable)
def test_func():
    assert istype(_func, tp.Callable)
Example #5
0
def test_generators_false():
    assert istype(_gen_1, tp.Callable) is False
    assert istype(_gen_2, tp.Callable) is False
Example #6
0
def test_generators_true():
    assert istype(_gen_1, tp.Generator) is True
    assert istype(_gen_2, tp.Generator) is True
def test_frozenset():
    _frozenset = frozenset()
    assert istype(_frozenset, frozenset) is True
    assert istype(_frozenset, tp.FrozenSet) is True
def test_set():
    _set = set()
    assert istype(_set, set) is True
    assert istype(_set, tp.Set) is True
def test_tuple():
    _tuple = tuple()
    assert istype(_tuple, tuple) is True
    assert istype(_tuple, tp.Tuple) is True
Example #10
0
def test_str():
    _str = "a"
    assert istype(_str, str) is True
Example #11
0
def test_none():
    _none = None
    assert istype(_none, None) is True
Example #12
0
def test_hashable():
    for i in (1, "str", b"bytes", True, None):
        assert istype(i, tp.Hashable) is True
    for i in (list(), dict()):
        assert istype(i, tp.Hashable) is False
Example #13
0
def test_bytes():
    _bytes = b"bytes"
    assert istype(_bytes, bytes) is True
    assert istype(_bytes, tp.ByteString) is True
Example #14
0
def test_bool():
    _bool = True
    assert istype(_bool, bool) is True
Example #15
0
def test_int():
    _int = 1
    assert istype(_int, int) is True