Minimal pycapnp
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import sys
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
@@ -62,93 +61,3 @@ def test_failed_import():
|
||||
|
||||
with pytest.raises(Exception):
|
||||
bar.foo = foo
|
||||
|
||||
|
||||
def test_defualt_import_hook():
|
||||
# Make sure any previous imports of addressbook_capnp are gone
|
||||
capnp.cleanup_global_schema_parser()
|
||||
|
||||
import addressbook_capnp # noqa: F401
|
||||
|
||||
|
||||
def test_dash_import():
|
||||
import addressbook_with_dashes_capnp # noqa: F401
|
||||
|
||||
|
||||
def test_spaces_import():
|
||||
import addressbook_with_spaces_capnp # noqa: F401
|
||||
|
||||
|
||||
def test_add_import_hook():
|
||||
capnp.add_import_hook()
|
||||
|
||||
# Make sure any previous imports of addressbook_capnp are gone
|
||||
capnp.cleanup_global_schema_parser()
|
||||
|
||||
import addressbook_capnp
|
||||
|
||||
addressbook_capnp.AddressBook.new_message()
|
||||
|
||||
|
||||
def test_multiple_add_import_hook():
|
||||
capnp.add_import_hook()
|
||||
capnp.add_import_hook()
|
||||
|
||||
# Make sure any previous imports of addressbook_capnp are gone
|
||||
capnp.cleanup_global_schema_parser()
|
||||
|
||||
import addressbook_capnp
|
||||
|
||||
addressbook_capnp.AddressBook.new_message()
|
||||
|
||||
|
||||
def test_remove_import_hook():
|
||||
capnp.add_import_hook()
|
||||
capnp.remove_import_hook()
|
||||
|
||||
if "addressbook_capnp" in sys.modules:
|
||||
# hack to deal with it being imported already
|
||||
del sys.modules["addressbook_capnp"]
|
||||
|
||||
with pytest.raises(ImportError):
|
||||
import addressbook_capnp # noqa: F401
|
||||
|
||||
|
||||
def test_bundled_import_hook():
|
||||
# stream.capnp should be bundled, or provided by the system capnproto
|
||||
capnp.add_import_hook()
|
||||
from capnp import stream_capnp # noqa: F401
|
||||
|
||||
|
||||
def test_nested_import():
|
||||
import schemas.parent_capnp # noqa: F401
|
||||
import schemas.child_capnp # noqa: F401
|
||||
|
||||
|
||||
async def test_load_capnp(foo):
|
||||
# test dynamically loading
|
||||
loader = capnp.SchemaLoader()
|
||||
loader.load(foo.Baz.schema.get_proto())
|
||||
loader.load_dynamic(foo.Qux.schema.get_proto().node)
|
||||
|
||||
schema = loader.get(foo.Baz.schema.get_proto().node.id).as_struct()
|
||||
assert "text" in schema.fieldnames
|
||||
assert "qux" in schema.fieldnames
|
||||
assert schema.fields["qux"].proto.slot.type.which == "struct"
|
||||
|
||||
class Wrapper(foo.Wrapper.Server):
|
||||
async def wrapped(self, object, **kwargs):
|
||||
assert isinstance(object, capnp.lib.capnp._DynamicObjectReader)
|
||||
baz_ = object.as_struct(schema)
|
||||
assert baz_.text == "test"
|
||||
assert baz_.qux.id == 2
|
||||
|
||||
# test calling into the wrapper with a Baz message.
|
||||
baz_ = foo.Baz.new_message()
|
||||
baz_.text = "test"
|
||||
baz_.qux.id = 2
|
||||
|
||||
async with capnp.kj_loop():
|
||||
wrapper = foo.Wrapper._new_client(Wrapper())
|
||||
remote = wrapper.wrapped(baz_)
|
||||
await remote
|
||||
|
||||
Reference in New Issue
Block a user