get rid of all warnings during tests

This commit is contained in:
Andrey Cizov
2019-07-13 16:36:58 +01:00
committed by Jacob Alexander
parent 7bce2f751a
commit d94d60db8b
3 changed files with 35 additions and 18 deletions

View File

@@ -359,7 +359,7 @@ def test_inheritance():
assert response.x == '26'
class TestPassedCap(capability.TestPassedCap.Server):
class PassedCapTest(capability.TestPassedCap.Server):
def foo(self, cap, _context, **kwargs):
def set_result(res):
_context.results.x = res.x
@@ -367,32 +367,32 @@ class TestPassedCap(capability.TestPassedCap.Server):
def test_null_cap():
client = capability.TestPassedCap._new_client(TestPassedCap())
client = capability.TestPassedCap._new_client(PassedCapTest())
assert client.foo(Server()).wait().x == '26'
with pytest.raises(capnp.KjException):
client.foo().wait()
class TestStructArg(capability.TestStructArg.Server):
class StructArgTest(capability.TestStructArg.Server):
def bar(self, a, b, **kwargs):
return a + str(b)
def test_struct_args():
client = capability.TestStructArg._new_client(TestStructArg())
client = capability.TestStructArg._new_client(StructArgTest())
assert client.bar(a='test', b=1).wait().c == 'test1'
with pytest.raises(capnp.KjException):
assert client.bar('test', 1).wait().c == 'test1'
class TestGeneric(capability.TestGeneric.Server):
class GenericTest(capability.TestGeneric.Server):
def foo(self, a, **kwargs):
return a.as_text() + 'test'
def test_generic():
client = capability.TestGeneric._new_client(TestGeneric())
client = capability.TestGeneric._new_client(GenericTest())
obj = capnp._MallocMessageBuilder().get_root_as_any()
obj.set_as_text("anypointer_")

View File

@@ -32,7 +32,6 @@ def test_simple_rpc_with_options():
remote = cap.foo(i=5)
_ = remote.wait()
def test_simple_rpc_bootstrap():
read, write = socket.socketpair()

View File

@@ -1,3 +1,6 @@
import warnings
from contextlib import contextmanager
import pytest
import capnp
import os
@@ -103,14 +106,23 @@ def test_roundtrip_bytes_packed(all_types):
msg = all_types.TestAllTypes.from_bytes_packed(message_bytes)
test_regression.check_all_types(msg)
@contextmanager
def _warnings(expected_count=2, expected_text='This message has already been written once.'):
with warnings.catch_warnings(record=True) as w:
yield
assert len(w) == expected_count
assert all(issubclass(x.category, UserWarning) for x in w), w
assert all(expected_text in str(x.message) for x in w), w
def test_roundtrip_file_multiple(all_types):
f = tempfile.TemporaryFile()
msg = all_types.TestAllTypes.new_message()
test_regression.init_all_types(msg)
msg.write(f)
msg.write(f)
msg.write(f)
with _warnings(2):
msg.write(f)
msg.write(f)
f.seek(0)
i = 0
@@ -125,8 +137,9 @@ def test_roundtrip_bytes_multiple(all_types):
test_regression.init_all_types(msg)
msgs = msg.to_bytes()
msgs += msg.to_bytes()
msgs += msg.to_bytes()
with _warnings(2):
msgs += msg.to_bytes()
msgs += msg.to_bytes()
i = 0
for msg in all_types.TestAllTypes.read_multiple_bytes(msgs):
@@ -140,8 +153,9 @@ def test_roundtrip_file_multiple_packed(all_types):
msg = all_types.TestAllTypes.new_message()
test_regression.init_all_types(msg)
msg.write_packed(f)
msg.write_packed(f)
msg.write_packed(f)
with _warnings(2):
msg.write_packed(f)
msg.write_packed(f)
f.seek(0)
i = 0
@@ -156,8 +170,9 @@ def test_roundtrip_bytes_multiple_packed(all_types):
test_regression.init_all_types(msg)
msgs = msg.to_bytes_packed()
msgs += msg.to_bytes_packed()
msgs += msg.to_bytes_packed()
with _warnings(2):
msgs += msg.to_bytes_packed()
msgs += msg.to_bytes_packed()
i = 0
for msg in all_types.TestAllTypes.read_multiple_bytes_packed(msgs):
@@ -175,7 +190,8 @@ def test_roundtrip_dict(all_types):
test_regression.init_all_types(msg)
d = msg.to_dict()
msg = all_types.TestAllTypes.from_dict(d)
with _warnings(1, expected_text="This method is deprecated and will be removed"):
msg = all_types.TestAllTypes.from_dict(d)
test_regression.check_all_types(msg)
@@ -187,7 +203,8 @@ def test_file_and_bytes(all_types):
f.seek(0)
assert f.read() == msg.to_bytes()
with _warnings(1):
assert f.read() == msg.to_bytes()
def test_file_and_bytes_packed(all_types):
@@ -198,7 +215,8 @@ def test_file_and_bytes_packed(all_types):
f.seek(0)
assert f.read() == msg.to_bytes_packed()
with _warnings(1):
assert f.read() == msg.to_bytes_packed()
def test_pickle(all_types):