Applying black formatting
- Fixing flake8 configuration to agree with black - Adding black validation check to github actions
This commit is contained in:
@@ -7,9 +7,11 @@ this_dir = os.path.dirname(__file__)
|
||||
|
||||
# flake8: noqa: E501
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def capability():
|
||||
return capnp.load(os.path.join(this_dir, 'test_capability.capnp'))
|
||||
return capnp.load(os.path.join(this_dir, "test_capability.capnp"))
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, val=1):
|
||||
@@ -22,27 +24,29 @@ class Server:
|
||||
return str(i * 5 + extra + self.val)
|
||||
|
||||
def buz(self, i, **kwargs):
|
||||
return i.host + '_test'
|
||||
return i.host + "_test"
|
||||
|
||||
|
||||
class PipelineServer:
|
||||
def getCap(self, n, inCap, _context, **kwargs):
|
||||
def _then(response):
|
||||
_results = _context.results
|
||||
_results.s = response.x + '_foo'
|
||||
_results.s = response.x + "_foo"
|
||||
_results.outBox.cap = capability().TestInterface._new_server(Server(100))
|
||||
|
||||
return inCap.foo(i=n).then(_then)
|
||||
|
||||
|
||||
def test_client(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
req = client._request('foo')
|
||||
req = client._request("foo")
|
||||
req.i = 5
|
||||
|
||||
remote = req.send()
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '26'
|
||||
assert response.x == "26"
|
||||
|
||||
req = client.foo_request()
|
||||
req.i = 5
|
||||
@@ -50,7 +54,7 @@ def test_client(capability):
|
||||
remote = req.send()
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '26'
|
||||
assert response.x == "26"
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
client.foo2_request()
|
||||
@@ -58,51 +62,51 @@ def test_client(capability):
|
||||
req = client.foo_request()
|
||||
|
||||
with pytest.raises(Exception):
|
||||
req.i = 'foo'
|
||||
req.i = "foo"
|
||||
|
||||
req = client.foo_request()
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
req.baz = 1
|
||||
|
||||
|
||||
def test_simple_client(capability):
|
||||
client = capability.TestInterface._new_client(Server())
|
||||
|
||||
remote = client._send('foo', i=5)
|
||||
remote = client._send("foo", i=5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '26'
|
||||
|
||||
assert response.x == "26"
|
||||
|
||||
remote = client.foo(i=5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '26'
|
||||
assert response.x == "26"
|
||||
|
||||
remote = client.foo(i=5, j=True)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '27'
|
||||
assert response.x == "27"
|
||||
|
||||
remote = client.foo(5)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '26'
|
||||
assert response.x == "26"
|
||||
|
||||
remote = client.foo(5, True)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '27'
|
||||
assert response.x == "27"
|
||||
|
||||
remote = client.foo(5, j=True)
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == '27'
|
||||
assert response.x == "27"
|
||||
|
||||
remote = client.buz(capability.TestSturdyRefHostId.new_message(host='localhost'))
|
||||
remote = client.buz(capability.TestSturdyRefHostId.new_message(host="localhost"))
|
||||
response = remote.wait()
|
||||
|
||||
assert response.x == 'localhost_test'
|
||||
assert response.x == "localhost_test"
|
||||
|
||||
with pytest.raises(Exception):
|
||||
remote = client.foo(5, 10)
|
||||
@@ -111,7 +115,7 @@ def test_simple_client(capability):
|
||||
remote = client.foo(5, True, 100)
|
||||
|
||||
with pytest.raises(Exception):
|
||||
remote = client.foo(i='foo')
|
||||
remote = client.foo(i="foo")
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
remote = client.foo2(i=5)
|
||||
@@ -119,15 +123,16 @@ def test_simple_client(capability):
|
||||
with pytest.raises(Exception):
|
||||
remote = client.foo(baz=5)
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_pipeline(capability):
|
||||
'''
|
||||
"""
|
||||
E capnp.lib.capnp.KjException: capnp/lib/capnp.pyx:61: failed: <class 'Failed'>:Fixture "capability" called directly. Fixtures are not meant to be called directly,
|
||||
E but are created automatically when test functions request them as parameters.
|
||||
E See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and
|
||||
E https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code.
|
||||
E stack: 7f680f7fce40 7f680f4f9250 7f680f4f4260 7f680f4fa9f0 7f680f4f6f50 7f680f4fb540 7f680f50dbf0 7f680f801768 7f680f7e5185 7f680f7e52dc 7f680f7a3a1d 7f68115cb459 7f68115cb713 7f68115fd2eb 7f6811637409 7f68115eb767 7f68115ece7e 7f681163448d 7f68115eb767 7f68115ece7e 7f681163448d 7f68115eb767 7f68115ec7d2 7f68115fd1cf 7f6811633b77 7f68115eb767 7f68115ec7d2 7f68115fd1cf 7f6811637409 7f68115ec632 7f68115fd1cf 7f6811637409
|
||||
'''
|
||||
"""
|
||||
client = capability.TestPipeline._new_client(PipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(Server())
|
||||
|
||||
@@ -137,10 +142,11 @@ def test_pipeline(capability):
|
||||
pipelinePromise = outCap.foo(i=10)
|
||||
|
||||
response = pipelinePromise.wait()
|
||||
assert response.x == '150'
|
||||
assert response.x == "150"
|
||||
|
||||
response = remote.wait()
|
||||
assert response.s == '26_foo'
|
||||
assert response.s == "26_foo"
|
||||
|
||||
|
||||
class BadServer:
|
||||
def __init__(self, val=1):
|
||||
@@ -150,27 +156,30 @@ class BadServer:
|
||||
extra = 0
|
||||
if j:
|
||||
extra = 1
|
||||
return str(i * 5 + extra + self.val), 10 # returning too many args
|
||||
return str(i * 5 + extra + self.val), 10 # returning too many args
|
||||
|
||||
|
||||
def test_exception_client(capability):
|
||||
client = capability.TestInterface._new_client(BadServer())
|
||||
|
||||
remote = client._send('foo', i=5)
|
||||
remote = client._send("foo", i=5)
|
||||
with pytest.raises(capnp.KjException):
|
||||
remote.wait()
|
||||
|
||||
|
||||
class BadPipelineServer:
|
||||
def getCap(self, n, inCap, _context, **kwargs):
|
||||
def _then(response):
|
||||
_results = _context.results
|
||||
_results.s = response.x + '_foo'
|
||||
_results.s = response.x + "_foo"
|
||||
_results.outBox.cap = capability().TestInterface._new_server(Server(100))
|
||||
|
||||
def _error(error):
|
||||
raise Exception('test was a success')
|
||||
raise Exception("test was a success")
|
||||
|
||||
return inCap.foo(i=n).then(_then, _error)
|
||||
|
||||
|
||||
def test_exception_chain(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
foo_client = capability.TestInterface._new_client(BadServer())
|
||||
@@ -180,7 +189,8 @@ def test_exception_chain(capability):
|
||||
try:
|
||||
remote.wait()
|
||||
except Exception as e:
|
||||
assert 'test was a success' in str(e)
|
||||
assert "test was a success" in str(e)
|
||||
|
||||
|
||||
def test_pipeline_exception(capability):
|
||||
client = capability.TestPipeline._new_client(BadPipelineServer())
|
||||
@@ -197,6 +207,7 @@ def test_pipeline_exception(capability):
|
||||
with pytest.raises(Exception):
|
||||
remote.wait()
|
||||
|
||||
|
||||
def test_casting(capability):
|
||||
client = capability.TestExtends._new_client(Server())
|
||||
client2 = client.upcast(capability.TestInterface)
|
||||
@@ -205,6 +216,7 @@ def test_casting(capability):
|
||||
with pytest.raises(Exception):
|
||||
client.upcast(capability.TestPipeline)
|
||||
|
||||
|
||||
class TailCallOrder:
|
||||
def __init__(self):
|
||||
self.count = -1
|
||||
@@ -213,6 +225,7 @@ class TailCallOrder:
|
||||
self.count += 1
|
||||
return self.count
|
||||
|
||||
|
||||
class TailCaller:
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
@@ -220,9 +233,10 @@ class TailCaller:
|
||||
def foo(self, i, callee, _context, **kwargs):
|
||||
self.count += 1
|
||||
|
||||
tail = callee.foo_request(i=i, t='from TailCaller')
|
||||
tail = callee.foo_request(i=i, t="from TailCaller")
|
||||
return _context.tail_call(tail)
|
||||
|
||||
|
||||
class TailCallee:
|
||||
def __init__(self):
|
||||
self.count = 0
|
||||
@@ -235,15 +249,16 @@ class TailCallee:
|
||||
results.t = t
|
||||
results.c = capability().TestCallOrder._new_server(TailCallOrder())
|
||||
|
||||
|
||||
@pytest.mark.xfail
|
||||
def test_tail_call(capability):
|
||||
'''
|
||||
"""
|
||||
E capnp.lib.capnp.KjException: capnp/lib/capnp.pyx:104: failed: <class 'Failed'>:Fixture "capability" called directly. Fixtures are not meant to be called directly,
|
||||
E but are created automatically when test functions request them as parameters.
|
||||
E See https://docs.pytest.org/en/latest/fixture.html for more information about fixtures, and
|
||||
E https://docs.pytest.org/en/latest/deprecations.html#calling-fixtures-directly about how to update your code.
|
||||
E stack: 7f680f4fb540 7f680f4fb1b0 7f680f4fb540 7f680f50dbf0 7f680f801768 7f680f7e5185 7f680f7e52dc 7f680f7a3a1d 7f68115cb459 7f68115cb713 7f68115fd2eb 7f6811637409 7f68115eb767 7f68115ece7e 7f681163448d 7f68115eb767 7f68115ece7e 7f681163448d 7f68115eb767 7f68115ec7d2 7f68115fd1cf 7f6811633b77 7f68115eb767 7f68115ec7d2 7f68115fd1cf 7f6811637409 7f68115ec632 7f68115fd1cf 7f6811637409 7f68115eb767 7f68115ece7e 7f68115c0ce7
|
||||
'''
|
||||
"""
|
||||
callee_server = TailCallee()
|
||||
caller_server = TailCaller()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user