From c9b495237e3ce0e715b00cdde9e9ad857f2b37c6 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Thu, 9 Jul 2026 19:09:56 +0800 Subject: [PATCH] test/stubgen: fill more tests on stubs --- tests/schemas/test_stubs.py | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tests/schemas/test_stubs.py b/tests/schemas/test_stubs.py index a8b1f99..5b0c61c 100644 --- a/tests/schemas/test_stubs.py +++ b/tests/schemas/test_stubs.py @@ -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.