From 977f471dec9d8330ead996755a34c6c3f15702db Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Wed, 19 Nov 2014 08:10:51 -0800 Subject: [PATCH] Add annotation tests for schema interface --- test/annotations.capnp | 15 +++++++++++++++ test/test_schema.py | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/annotations.capnp diff --git a/test/annotations.capnp b/test/annotations.capnp new file mode 100644 index 0000000..b372eda --- /dev/null +++ b/test/annotations.capnp @@ -0,0 +1,15 @@ +@0xfb9a160831eee9bb; + +struct AnnotationStruct { + test @0: Int32; +} + +annotation test1(*): Text; +annotation test2(*): AnnotationStruct; +annotation test3(*): List(AnnotationStruct); + +$test1("TestFile"); + +struct TestAnnotationOne $test1("Test") { } +struct TestAnnotationTwo $test2(test = 100) { } +struct TestAnnotationThree $test3([(test=100), (test=101)]) { } diff --git a/test/test_schema.py b/test/test_schema.py index 61899b8..eff28c1 100644 --- a/test/test_schema.py +++ b/test/test_schema.py @@ -10,9 +10,15 @@ def addressbook(): return capnp.load(os.path.join(this_dir, 'addressbook.capnp')) +@pytest.fixture +def annotations(): + return capnp.load(os.path.join(this_dir, 'annotations.capnp')) + + def test_basic_schema(addressbook): assert addressbook.Person.schema.fieldnames[0] == 'id' + def test_list_schema(addressbook): peopleField = addressbook.AddressBook.schema.fields['people'] personType = peopleField.schema.elementType @@ -22,3 +28,19 @@ def test_list_schema(addressbook): personListSchema = capnp.ListSchema(addressbook.Person) assert personListSchema.elementType.node.id == addressbook.Person.schema.node.id + + +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] + annotation_list = annotation.value.list.as_list(capnp.ListSchema(annotations.AnnotationStruct)) + assert annotation_list[0].test == 100 + assert annotation_list[1].test == 101 +