Beispiel #1
0
def test_typed(obj, input, getter, type, check):
    wrapped = typed(obj)
    result = wrapped(input)
    if getter:
        result = getter(result)
    assert check(wrapped)
    assert isinstance(result, type)
Beispiel #2
0
def test_typed_varargs(func, args, kwargs, check):
    wrapped = typed(func)
    result = wrapped(*args, **kwargs)

    assert check(result)
Beispiel #3
0
def test_ensure_invalid():
    with pytest.raises(TypeError):
        typed(1)
Beispiel #4
0
)
def test_get_origin_returns_origin(annotation, origin):
    detected = get_origin(annotation)
    assert detected is origin


def test_eval_invalid():
    processed, result = safe_eval("{")
    assert not processed
    assert result == "{"


@pytest.mark.parametrize(
    argnames=("instance", "attr", "value", "type"),
    argvalues=[
        (typed(objects.Data)("foo"), "foo", 1, str),
        (typed(objects.NoParams)(), "var", 1, str),
    ],
    ids=objects.get_id,
)
def test_setattr(instance, attr, value, type):
    setattr(instance, attr, value)
    assert isinstance(getattr(instance, attr), type)


def test_register():
    class MyCustomClass:  # pragma: nocover
        def __init__(self, value: str):
            self.value = value

    class MyOtherCustomClass:  # pragma: nocover