Add as_interface/as_list methods to _DynamicObject*
This commit is contained in:
@@ -4,21 +4,48 @@ import os
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
|
||||
@pytest.fixture
|
||||
def object():
|
||||
return capnp.load(os.path.join(this_dir, 'object.capnp'))
|
||||
|
||||
def test_object_basic(object):
|
||||
obj = object.TestObject.new_message()
|
||||
person = obj.object.as_struct(object.Person)
|
||||
@pytest.fixture
|
||||
def addressbook():
|
||||
return capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
||||
|
||||
|
||||
def test_object_basic(addressbook):
|
||||
obj = capnp._MallocMessageBuilder().get_root_as_any()
|
||||
person = obj.as_struct(addressbook.Person)
|
||||
person.name = 'test'
|
||||
person.id = 1000
|
||||
|
||||
same_person = obj.object.as_struct(object.Person)
|
||||
same_person = obj.as_struct(addressbook.Person)
|
||||
assert same_person.name == 'test'
|
||||
assert same_person.id == 1000
|
||||
|
||||
obj_r = obj.as_reader()
|
||||
same_person = obj_r.object.as_struct(object.Person)
|
||||
same_person = obj_r.as_struct(addressbook.Person)
|
||||
assert same_person.name == 'test'
|
||||
assert same_person.id == 1000
|
||||
|
||||
|
||||
def test_object_list(addressbook):
|
||||
obj = capnp._MallocMessageBuilder().get_root_as_any()
|
||||
listSchema = capnp.ListSchema(addressbook.Person)
|
||||
people = obj.init_as_list(listSchema, 2)
|
||||
person = people[0]
|
||||
person.name = 'test'
|
||||
person.id = 1000
|
||||
person = people[1]
|
||||
person.name = 'test2'
|
||||
person.id = 1001
|
||||
|
||||
same_person = obj.as_list(listSchema)
|
||||
assert same_person[0].name == 'test'
|
||||
assert same_person[0].id == 1000
|
||||
assert same_person[1].name == 'test2'
|
||||
assert same_person[1].id == 1001
|
||||
|
||||
obj_r = obj.as_reader()
|
||||
same_person = obj_r.as_list(listSchema)
|
||||
assert same_person[0].name == 'test'
|
||||
assert same_person[0].id == 1000
|
||||
assert same_person[1].name == 'test2'
|
||||
assert same_person[1].id == 1001
|
||||
|
||||
Reference in New Issue
Block a user