test/stubgen: fill more tests on stubs

This commit is contained in:
2026-07-09 19:09:56 +08:00
parent 9a19ffb0ce
commit c9b495237e
+37 -2
View File
@@ -16,6 +16,9 @@ if str(_HERE) not in sys.path:
sys.path.insert(0, str(_HERE))
import capnp # pyright: ignore[reportMissingTypeStubs, reportUnusedImport] # activates import hook
import test_generics_capnp
import test_interface_capnp
import test_nested_capnp
import test_simple_capnp
@@ -56,7 +59,6 @@ class TestNestedStub:
"""test_nested.capnp — nested types + lists."""
def test_nested_message(self) -> None:
import test_nested_capnp
ab = test_nested_capnp.AddressBook.new_message()
assert ab.people is not None
@@ -65,6 +67,39 @@ class TestGenericsStub:
"""test_generics.capnp — generic structs."""
def test_holder_loads(self) -> None:
import test_generics_capnp
c = test_generics_capnp.Container.new_message()
assert c is not None
class TestInterfaceStub:
"""test_interface.capnp — interfaces + method params."""
def test_calcserver_loads(self) -> None:
cs = test_interface_capnp.CalcServer.new_message()
assert cs is not None
class TestAddressBookStub:
"""addressbook.capnp — classic example."""
def test_person_new_message(self) -> None:
import addressbook_capnp
p = addressbook_capnp.Person.new_message(
name="Alice", email="alice@example.com"
)
assert p.name == "Alice"
def test_addressbook_new_message(self) -> None:
import addressbook_capnp
ab = addressbook_capnp.AddressBook.new_message()
assert ab.people is not None
# dummy.capnp runtime tests skipped — its annotation imports (c.capnp,
# c++.capnp) cause pycapnp's C++ SchemaParser to SIGABRT. The generated
# .pyi passes static type-checking and `capnp compile -opy` succeeds.
# Note: multi/consumer.capnp cross-file import test skipped —
# pycapnp's SchemaParser crashes when resolving annotation imports
# across schema files. The .pyi stubs are still generated and kept.