Change server instantion to be inherited

This commit is contained in:
Jason Paryani
2013-12-09 17:13:43 -08:00
parent 362a50e34a
commit 3f7c3ae023
6 changed files with 318 additions and 44 deletions

View File

@@ -2,13 +2,9 @@ import pytest
import capnp
import os
this_dir = os.path.dirname(__file__)
import test_capability_capnp as capability
@pytest.fixture
def capability():
return capnp.load(os.path.join(this_dir, 'test_capability.capnp'))
class Server:
class Server(capability.TestInterface.Server):
def __init__(self, val=1):
self.val = val
@@ -21,16 +17,16 @@ class Server:
def buz(self, i, **kwargs):
return i.host + '_test'
class PipelineServer:
class PipelineServer(capability.TestPipeline.Server):
def getCap(self, n, inCap, _context, **kwargs):
def _then(response):
_results = _context.results
_results.s = response.x + '_foo'
_results.outBox.cap = capability().TestInterface.new_server(Server(100))
_results.outBox.cap = Server(100)
return inCap.foo(i=n).then(_then)
def test_client(capability):
def test_client():
client = capability.TestInterface._new_client(Server())
req = client._request('foo')
@@ -62,7 +58,7 @@ def test_client(capability):
with pytest.raises(ValueError):
req.baz = 1
def test_simple_client(capability):
def test_simple_client():
client = capability.TestInterface._new_client(Server())
remote = client._send('foo', i=5)
@@ -116,7 +112,7 @@ def test_simple_client(capability):
with pytest.raises(ValueError):
remote = client.foo(baz=5)
def test_pipeline(capability):
def test_pipeline():
client = capability.TestPipeline._new_client(PipelineServer())
foo_client = capability.TestInterface._new_client(Server())
@@ -131,7 +127,7 @@ def test_pipeline(capability):
response = remote.wait()
assert response.s == '26_foo'
class BadServer:
class BadServer(capability.TestInterface.Server):
def __init__(self, val=1):
self.val = val
@@ -141,25 +137,25 @@ class BadServer:
extra = 1
return str(i * 5 + extra + self.val), 10 # returning too many args
def test_exception_client(capability):
def test_exception_client():
client = capability.TestInterface._new_client(BadServer())
remote = client._send('foo', i=5)
with pytest.raises(capnp.KjException):
remote.wait()
class BadPipelineServer:
class BadPipelineServer(capability.TestPipeline.Server):
def getCap(self, n, inCap, _context, **kwargs):
def _then(response):
_results = _context.results
_results.s = response.x + '_foo'
_results.outBox.cap = capability().TestInterface.new_server(Server(100))
_results.outBox.cap = Server(100)
def _error(error):
raise Exception('test was a success')
return inCap.foo(i=n).then(_then, _error)
def test_exception_chain(capability):
def test_exception_chain():
client = capability.TestPipeline._new_client(BadPipelineServer())
foo_client = capability.TestInterface._new_client(BadServer())
@@ -170,7 +166,7 @@ def test_exception_chain(capability):
except Exception as e:
assert 'test was a success' in str(e)
def test_pipeline_exception(capability):
def test_pipeline_exception():
client = capability.TestPipeline._new_client(BadPipelineServer())
foo_client = capability.TestInterface._new_client(BadServer())
@@ -185,7 +181,7 @@ def test_pipeline_exception(capability):
with pytest.raises(Exception):
remote.wait()
def test_casting(capability):
def test_casting():
client = capability.TestExtends._new_client(Server())
client2 = client.upcast(capability.TestInterface)
client3 = client2.cast_as(capability.TestInterface)
@@ -193,7 +189,7 @@ def test_casting(capability):
with pytest.raises(Exception):
client.upcast(capability.TestPipeline)
class TailCallOrder:
class TailCallOrder(capability.TestCallOrder.Server):
def __init__(self):
self.count = -1
@@ -201,7 +197,7 @@ class TailCallOrder:
self.count += 1
return self.count
class TailCaller:
class TailCaller(capability.TestTailCaller.Server):
def __init__(self):
self.count = 0
@@ -211,7 +207,7 @@ class TailCaller:
tail = callee.foo_request(i=i, t='from TailCaller')
return _context.tail_call(tail)
class TailCallee:
class TailCallee(capability.TestTailCallee.Server):
def __init__(self):
self.count = 0
@@ -221,9 +217,9 @@ class TailCallee:
results = _context.results
results.i = i
results.t = t
results.c = capability().TestCallOrder.new_server(TailCallOrder())
results.c = TailCallOrder()
def test_tail_call(capability):
def test_tail_call():
callee_server = TailCallee()
caller_server = TailCaller()