Skip to content

Commit 30d4dd2

Browse files
committed
Added stubgen+mypy test
1 parent 885a5f6 commit 30d4dd2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--extra-index-url=https://www.graalvm.org/python/wheels
22
--only-binary=:all:
33
build>=1
4+
mypy
45
numpy~=1.23.0; python_version=="3.8" and platform_python_implementation=="PyPy"
56
numpy~=1.25.0; python_version=="3.9" and platform_python_implementation=="PyPy"
67
numpy~=2.2.0; python_version=="3.10" and platform_python_implementation=="PyPy"

tests/test_stubgen.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
4+
5+
import pybind11_stubgen as stubgen
6+
from mypy import api
7+
38
from pybind11_tests import stubgen as m
49

510

6-
def test_stubgen() -> None:
11+
def test_stubgen(tmp_path: Path) -> None:
712
assert m.add_int(1, 2) == 3
13+
14+
stubgen.main(
15+
[
16+
"pybind11_tests.stubgen",
17+
"-o",
18+
tmp_path.as_posix(),
19+
]
20+
)
21+
print(f"Stubgen output: {tmp_path.as_posix()}")
22+
stub_file = tmp_path / "pybind11_tests" / "stubgen.pyi"
23+
assert stub_file.exists()
24+
stub_content = stub_file.read_text()
25+
assert (
26+
"def add_int(a: typing.SupportsInt, b: typing.SupportsInt) -> int:"
27+
in stub_content
28+
)
29+
normal_report, error_report, exit_status = api.run([stub_file.as_posix()])
30+
print("Normal report:")
31+
print(normal_report)
32+
print("Error report:")
33+
print(error_report)
34+
assert exit_status == 0
35+
assert "Success: no issues found in 1 source file" in normal_report

0 commit comments

Comments
 (0)