From 892e87b747035a1e8c9c1b9f68836b03eff3c9d6 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Wed, 28 Aug 2013 23:13:38 -0700 Subject: [PATCH] Add initial tests --- test/addressbook.capnp | 34 ++++++++++++++++++++++++++++++++++ test/test_load.py | 24 ++++++++++++++++++++++++ tox.ini | 10 ++++++++++ 3 files changed, 68 insertions(+) create mode 100644 test/addressbook.capnp create mode 100644 test/test_load.py create mode 100644 tox.ini diff --git a/test/addressbook.capnp b/test/addressbook.capnp new file mode 100644 index 0000000..e1cd77c --- /dev/null +++ b/test/addressbook.capnp @@ -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); +} + diff --git a/test/test_load.py b/test/test_load.py new file mode 100644 index 0000000..bebd150 --- /dev/null +++ b/test/test_load.py @@ -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 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..700ad93 --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist = py26,py27,py32,py33 + +[testenv] +deps= + pytest + cython + +commands = + py.test