Ejemplo n.º 1
0
def test_init() -> None:
    """It should have default spec properties."""
    subject = Spec(source=None, name=None)

    assert subject.get_signature() is None
    assert subject.get_class_type() is None
    assert subject.get_is_async() is False
Ejemplo n.º 2
0
def test_get_signature_no_type_hints() -> None:
    """It should gracefully degrade if a class's type hints cannot be resolved."""
    class _BadTypeHints:
        _not_ok: "None[Any]"

        def _ok(self, hello: str) -> None:
            ...

    subject = Spec(source=_BadTypeHints, name=None).get_child_spec("_ok")

    assert subject.get_signature() == inspect.Signature(
        parameters=[
            inspect.Parameter(
                name="hello",
                kind=inspect.Parameter.POSITIONAL_OR_KEYWORD,
                annotation=str,
            )
        ],
        return_annotation=None,
    )
Ejemplo n.º 3
0
def test_get_signature(
    subject: Spec,
    expected_signature: Optional[inspect.Signature],
) -> None:
    """It should inspect the spec source's signature."""
    assert subject.get_signature() == expected_signature