Remove .capnp fixture from test_capability_context.py
Using a fixture makes things more complicated. If we want to test explicit capnp.load() functionality, we can do that separately
This commit is contained in:
@@ -1,20 +1,10 @@
|
|||||||
import os
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import capnp
|
import capnp
|
||||||
|
import test_capability_capnp as capability
|
||||||
this_dir = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
# flake8: noqa: E501
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
class Server(capability.TestInterface.Server):
|
||||||
def capability():
|
|
||||||
capnp.cleanup_global_schema_parser()
|
|
||||||
return capnp.load(os.path.join(this_dir, "test_capability.capnp"))
|
|
||||||
|
|
||||||
|
|
||||||
class Server:
|
|
||||||
def __init__(self, val=1):
|
def __init__(self, val=1):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
@@ -28,19 +18,14 @@ class Server:
|
|||||||
context.results.x = context.params.i.host + "_test"
|
context.results.x = context.params.i.host + "_test"
|
||||||
|
|
||||||
|
|
||||||
class PipelineServer:
|
class PipelineServer(capability.TestPipeline.Server):
|
||||||
def __init__(self, capability):
|
|
||||||
self.capability = capability
|
|
||||||
|
|
||||||
async def getCap_context(self, context):
|
async def getCap_context(self, context):
|
||||||
response = await context.params.inCap.foo(i=context.params.n)
|
response = await context.params.inCap.foo(i=context.params.n)
|
||||||
context.results.s = response.x + "_foo"
|
context.results.s = response.x + "_foo"
|
||||||
context.results.outBox.cap = self.capability.TestInterface._new_server(
|
context.results.outBox.cap = Server(100)
|
||||||
Server(100)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_client_context(capability):
|
async def test_client_context():
|
||||||
client = capability.TestInterface._new_client(Server())
|
client = capability.TestInterface._new_client(Server())
|
||||||
|
|
||||||
req = client._request("foo")
|
req = client._request("foo")
|
||||||
@@ -73,7 +58,7 @@ async def test_client_context(capability):
|
|||||||
req.baz = 1
|
req.baz = 1
|
||||||
|
|
||||||
|
|
||||||
async def test_simple_client_context(capability):
|
async def test_simple_client_context():
|
||||||
client = capability.TestInterface._new_client(Server())
|
client = capability.TestInterface._new_client(Server())
|
||||||
|
|
||||||
remote = client._send("foo", i=5)
|
remote = client._send("foo", i=5)
|
||||||
@@ -127,8 +112,8 @@ async def test_simple_client_context(capability):
|
|||||||
remote = client.foo(baz=5)
|
remote = client.foo(baz=5)
|
||||||
|
|
||||||
|
|
||||||
async def test_pipeline_context(capability):
|
async def test_pipeline_context():
|
||||||
client = capability.TestPipeline._new_client(PipelineServer(capability))
|
client = capability.TestPipeline._new_client(PipelineServer())
|
||||||
foo_client = capability.TestInterface._new_client(Server())
|
foo_client = capability.TestInterface._new_client(Server())
|
||||||
|
|
||||||
remote = client.getCap(n=5, inCap=foo_client)
|
remote = client.getCap(n=5, inCap=foo_client)
|
||||||
@@ -143,7 +128,7 @@ async def test_pipeline_context(capability):
|
|||||||
assert response.s == "26_foo"
|
assert response.s == "26_foo"
|
||||||
|
|
||||||
|
|
||||||
class BadServer:
|
class BadServer(capability.TestInterface.Server):
|
||||||
def __init__(self, val=1):
|
def __init__(self, val=1):
|
||||||
self.val = val
|
self.val = val
|
||||||
|
|
||||||
@@ -152,7 +137,7 @@ class BadServer:
|
|||||||
context.results.x2 = 5 # raises exception
|
context.results.x2 = 5 # raises exception
|
||||||
|
|
||||||
|
|
||||||
async def test_exception_client_context(capability):
|
async def test_exception_client_context():
|
||||||
client = capability.TestInterface._new_client(BadServer())
|
client = capability.TestInterface._new_client(BadServer())
|
||||||
|
|
||||||
remote = client._send("foo", i=5)
|
remote = client._send("foo", i=5)
|
||||||
@@ -160,10 +145,7 @@ async def test_exception_client_context(capability):
|
|||||||
await remote
|
await remote
|
||||||
|
|
||||||
|
|
||||||
class BadPipelineServer:
|
class BadPipelineServer(capability.TestPipeline.Server):
|
||||||
def __init__(self, capability):
|
|
||||||
self.capability = capability
|
|
||||||
|
|
||||||
async def getCap_context(self, context):
|
async def getCap_context(self, context):
|
||||||
try:
|
try:
|
||||||
await context.params.inCap.foo(i=context.params.n)
|
await context.params.inCap.foo(i=context.params.n)
|
||||||
@@ -171,8 +153,8 @@ class BadPipelineServer:
|
|||||||
raise Exception("test was a success")
|
raise Exception("test was a success")
|
||||||
|
|
||||||
|
|
||||||
async def test_exception_chain_context(capability):
|
async def test_exception_chain_context():
|
||||||
client = capability.TestPipeline._new_client(BadPipelineServer(capability))
|
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||||
foo_client = capability.TestInterface._new_client(BadServer())
|
foo_client = capability.TestInterface._new_client(BadServer())
|
||||||
|
|
||||||
remote = client.getCap(n=5, inCap=foo_client)
|
remote = client.getCap(n=5, inCap=foo_client)
|
||||||
@@ -183,8 +165,8 @@ async def test_exception_chain_context(capability):
|
|||||||
assert "test was a success" in str(e)
|
assert "test was a success" in str(e)
|
||||||
|
|
||||||
|
|
||||||
async def test_pipeline_exception_context(capability):
|
async def test_pipeline_exception_context():
|
||||||
client = capability.TestPipeline._new_client(BadPipelineServer(capability))
|
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||||
foo_client = capability.TestInterface._new_client(BadServer())
|
foo_client = capability.TestInterface._new_client(BadServer())
|
||||||
|
|
||||||
remote = client.getCap(n=5, inCap=foo_client)
|
remote = client.getCap(n=5, inCap=foo_client)
|
||||||
@@ -199,7 +181,7 @@ async def test_pipeline_exception_context(capability):
|
|||||||
await remote
|
await remote
|
||||||
|
|
||||||
|
|
||||||
async def test_casting_context(capability):
|
async def test_casting_context():
|
||||||
client = capability.TestExtends._new_client(Server())
|
client = capability.TestExtends._new_client(Server())
|
||||||
client2 = client.upcast(capability.TestInterface)
|
client2 = client.upcast(capability.TestInterface)
|
||||||
_ = client2.cast_as(capability.TestInterface)
|
_ = client2.cast_as(capability.TestInterface)
|
||||||
@@ -208,7 +190,7 @@ async def test_casting_context(capability):
|
|||||||
client.upcast(capability.TestPipeline)
|
client.upcast(capability.TestPipeline)
|
||||||
|
|
||||||
|
|
||||||
class TailCallOrder:
|
class TailCallOrder(capability.TestCallOrder.Server):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = -1
|
self.count = -1
|
||||||
|
|
||||||
@@ -217,7 +199,7 @@ class TailCallOrder:
|
|||||||
context.results.n = self.count
|
context.results.n = self.count
|
||||||
|
|
||||||
|
|
||||||
class TailCaller:
|
class TailCaller(capability.TestTailCaller.Server):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
@@ -230,10 +212,9 @@ class TailCaller:
|
|||||||
await context.tail_call(tail)
|
await context.tail_call(tail)
|
||||||
|
|
||||||
|
|
||||||
class TailCallee:
|
class TailCallee(capability.TestTailCallee.Server):
|
||||||
def __init__(self, capability):
|
def __init__(self):
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.capability = capability
|
|
||||||
|
|
||||||
async def foo_context(self, context):
|
async def foo_context(self, context):
|
||||||
self.count += 1
|
self.count += 1
|
||||||
@@ -241,11 +222,11 @@ class TailCallee:
|
|||||||
results = context.results
|
results = context.results
|
||||||
results.i = context.params.i
|
results.i = context.params.i
|
||||||
results.t = context.params.t
|
results.t = context.params.t
|
||||||
results.c = self.capability.TestCallOrder._new_server(TailCallOrder())
|
results.c = TailCallOrder()
|
||||||
|
|
||||||
|
|
||||||
async def test_tail_call(capability):
|
async def test_tail_call():
|
||||||
callee_server = TailCallee(capability)
|
callee_server = TailCallee()
|
||||||
caller_server = TailCaller()
|
caller_server = TailCaller()
|
||||||
|
|
||||||
callee = capability.TestTailCallee._new_client(callee_server)
|
callee = capability.TestTailCallee._new_client(callee_server)
|
||||||
|
|||||||
Reference in New Issue
Block a user