Add handling of DynamicObject
This commit is contained in:
21
test/object.capnp
Normal file
21
test/object.capnp
Normal file
@@ -0,0 +1,21 @@
|
||||
@0x8186ddb142b58556;
|
||||
|
||||
struct Person {
|
||||
id @0 :UInt32;
|
||||
name @1 :Text;
|
||||
}
|
||||
|
||||
struct Place {
|
||||
id @0 :UInt32;
|
||||
name @1 :Text;
|
||||
}
|
||||
|
||||
struct Thing {
|
||||
id @0 :UInt64;
|
||||
value @1 :UInt64;
|
||||
}
|
||||
|
||||
struct TestObject {
|
||||
object @0 :Object;
|
||||
}
|
||||
|
||||
25
test/test_object.py
Normal file
25
test/test_object.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
import capnp
|
||||
import os
|
||||
import math
|
||||
|
||||
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)
|
||||
person.name = 'test'
|
||||
person.id = 1000
|
||||
|
||||
same_person = obj.object.as_struct(object.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)
|
||||
assert same_person.name == 'test'
|
||||
assert same_person.id == 1000
|
||||
Reference in New Issue
Block a user