2014-11-19 02:04:57 -08:00
|
|
|
import pytest
|
|
|
|
import capnp
|
|
|
|
import os
|
|
|
|
|
|
|
|
this_dir = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def addressbook():
|
|
|
|
return capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
|
|
|
|
|
|
|
|
2014-11-19 08:10:51 -08:00
|
|
|
@pytest.fixture
|
|
|
|
def annotations():
|
|
|
|
return capnp.load(os.path.join(this_dir, 'annotations.capnp'))
|
|
|
|
|
|
|
|
|
2014-11-19 02:04:57 -08:00
|
|
|
def test_basic_schema(addressbook):
|
|
|
|
assert addressbook.Person.schema.fieldnames[0] == 'id'
|
|
|
|
|
2014-11-19 08:10:51 -08:00
|
|
|
|
2014-11-19 02:04:57 -08:00
|
|
|
def test_list_schema(addressbook):
|
|
|
|
peopleField = addressbook.AddressBook.schema.fields['people']
|
|
|
|
personType = peopleField.schema.elementType
|
|
|
|
|
|
|
|
assert personType.node.id == addressbook.Person.schema.node.id
|
2014-11-19 02:19:21 -08:00
|
|
|
|
2020-06-08 00:31:33 -07:00
|
|
|
personListSchema = capnp._ListSchema(addressbook.Person)
|
2014-11-19 02:19:21 -08:00
|
|
|
|
|
|
|
assert personListSchema.elementType.node.id == addressbook.Person.schema.node.id
|
2014-11-19 08:10:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
def test_annotations(annotations):
|
|
|
|
assert annotations.schema.node.annotations[0].value.text == 'TestFile'
|
|
|
|
|
|
|
|
annotation = annotations.TestAnnotationOne.schema.node.annotations[0]
|
|
|
|
assert annotation.value.text == 'Test'
|
|
|
|
|
|
|
|
annotation = annotations.TestAnnotationTwo.schema.node.annotations[0]
|
|
|
|
assert annotation.value.struct.as_struct(annotations.AnnotationStruct).test == 100
|
|
|
|
|
|
|
|
annotation = annotations.TestAnnotationThree.schema.node.annotations[0]
|
2020-06-08 00:31:33 -07:00
|
|
|
annotation_list = annotation.value.list.as_list(capnp._ListSchema(annotations.AnnotationStruct))
|
2014-11-19 08:10:51 -08:00
|
|
|
assert annotation_list[0].test == 100
|
|
|
|
assert annotation_list[1].test == 101
|
|
|
|
|
2014-11-20 10:24:10 -08:00
|
|
|
annotation = annotations.TestAnnotationFour.schema.node.annotations[0]
|
2020-06-08 00:31:33 -07:00
|
|
|
annotation_list = annotation.value.list.as_list(capnp._ListSchema(capnp.types.UInt16))
|
2014-11-20 10:24:10 -08:00
|
|
|
assert annotation_list[0] == 200
|
|
|
|
assert annotation_list[1] == 201
|