-
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtest_doc_pyi.py
More file actions
50 lines (37 loc) · 1.24 KB
/
test_doc_pyi.py
File metadata and controls
50 lines (37 loc) · 1.24 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
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
def test_invalid_imported_stub_file(monkeypatch):
monkeypatch.setattr(
doc_pyi,
"find_stub_file",
lambda m: here / "import_err/err/__init__.py" if m == "inspect" else None,
)
with pytest.warns(
UserWarning, match=r"Error parsing type stubs[\s\S]+RuntimeError"
):
_ = doc.Module(doc).members