Add initial tests

This commit is contained in:
Jason Paryani
2013-08-28 23:13:38 -07:00
parent 7d59df357c
commit 892e87b747
3 changed files with 68 additions and 0 deletions

34
test/addressbook.capnp Normal file
View File

@@ -0,0 +1,34 @@
@0x934efea7f017fff0;
const qux :UInt32 = 123;
struct Person {
id @0 :UInt32;
name @1 :Text;
email @2 :Text;
phones @3 :List(PhoneNumber);
struct PhoneNumber {
number @0 :Text;
type @1 :Type;
enum Type {
mobile @0;
home @1;
work @2;
}
}
employment :union {
unemployed @4 :Void;
employer @5 :Text;
school @6 :Text;
selfEmployed @7 :Void;
# We assume that a person is only one of these.
}
}
struct AddressBook {
people @0 :List(Person);
}

24
test/test_load.py Normal file
View File

@@ -0,0 +1,24 @@
import pytest
import capnp
from capnp import _capnp
import os
this_dir = os.path.dirname(__file__)
@pytest.fixture
def addressbook():
return capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
def test_basic_load():
capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
def test_constants(addressbook):
assert addressbook.qux == 123
def test_classes(addressbook):
assert addressbook.AddressBook
assert addressbook.Person
def test_schemas(addressbook):
assert type(addressbook.AddressBook.schema) is _capnp._StructSchema
assert type(addressbook.Person.schema) is _capnp._StructSchema