Пример #1
0
def test_type_matches_list_str(a):
    assert type_matches(a, "List[str]")
    assert not type_matches((1, 2, 3), "List[str]")
    assert not type_matches([1, 2, 3], "List[str]")
    assert not type_matches(["foo", 2, 3], "List[str]")
    assert not type_matches(a, "List[int]")
    assert not type_matches(a, "List[float]")
    assert not type_matches(a, "List[complex]")
Пример #2
0
def test_type_matches_list_complex(a):
    assert type_matches(a, "List[complex]")
    assert not type_matches((1 + 1j, 2 + 2j, 3 + 3j), "List[complex]")
    assert not type_matches([1, 2, 3], "List[complex]")
    assert not type_matches([1 + 1j, 2.0, 3], "List[complex]")
    assert not type_matches(a, "List[str]")
    assert not type_matches(a, "List[int]")
    assert not type_matches(a, "List[float]")
Пример #3
0
def test_type_matches_complex(a):
    assert type_matches(a, "complex")
    assert not type_matches(a, "str")
    assert not type_matches(a, "int")
    assert not type_matches(a, "float")
Пример #4
0
def test_type_matches_bool(a):
    assert type_matches(a, "bool")
    assert not type_matches(0, "bool")
Пример #5
0
def test_type_matches_unexpected():
    with pytest.raises(ValueError):
        assert type_matches("example", "weird")
        assert type_matches("example", "List[strange]")