1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
from pathlib import Path
import types
import pytest
from pdoc import doc
from pdoc import doc_pyi
here = Path(__file__).parent.absolute()
def test_type_stub_mismatch():
def foo_func():
"""I'm a func"""
class foo_cls:
"""I'm a cls"""
target = types.ModuleType("test")
target.__dict__["foo"] = foo_func
target.__dict__["__all__"] = ["foo"]
stub = types.ModuleType("test")
stub.__dict__["foo"] = foo_cls
stub.__dict__["__all__"] = ["foo"]
with pytest.warns(UserWarning, match="Error processing type stub"):
doc_pyi._patch_doc(doc.Module(target), doc.Module(stub))
def test_invalid_stub_file(monkeypatch):
monkeypatch.setattr(
doc_pyi, "find_stub_file", lambda m: here / "import_err/err/__init__.py"
)
with pytest.warns(
UserWarning, match=r"Error parsing type stubs[\s\S]+RuntimeError"
):
_ = doc.Module(doc).members
|