adapted test cases to:

- work with contextual from_bytes()
- add regression test against original issue with buf release (see test_roundtrip_bytes_buffer)
This commit is contained in:
Bernhard Liebl 2022-01-18 12:13:12 +01:00
parent 4b75fe3b5e
commit e2f3e5da46

View file

@ -46,8 +46,8 @@ def test_roundtrip_bytes(all_types):
test_regression.init_all_types(msg) test_regression.init_all_types(msg)
message_bytes = msg.to_bytes() message_bytes = msg.to_bytes()
msg = all_types.TestAllTypes.from_bytes(message_bytes) with all_types.TestAllTypes.from_bytes(message_bytes) as msg:
test_regression.check_all_types(msg) test_regression.check_all_types(msg)
@pytest.mark.skipif( @pytest.mark.skipif(
@ -77,8 +77,8 @@ def test_roundtrip_bytes_mmap(all_types):
f.seek(0) f.seek(0)
memory = mmap.mmap(f.fileno(), length) memory = mmap.mmap(f.fileno(), length)
msg = all_types.TestAllTypes.from_bytes(memory) with all_types.TestAllTypes.from_bytes(memory) as msg:
test_regression.check_all_types(msg) test_regression.check_all_types(msg)
@pytest.mark.skipif( @pytest.mark.skipif(
@ -90,13 +90,17 @@ def test_roundtrip_bytes_buffer(all_types):
b = msg.to_bytes() b = msg.to_bytes()
v = memoryview(b) v = memoryview(b)
msg = all_types.TestAllTypes.from_bytes(v) try:
test_regression.check_all_types(msg) with all_types.TestAllTypes.from_bytes(v) as msg:
test_regression.check_all_types(msg)
finally:
v.release()
def test_roundtrip_bytes_fail(all_types): def test_roundtrip_bytes_fail(all_types):
with pytest.raises(TypeError): with pytest.raises(TypeError):
all_types.TestAllTypes.from_bytes(42) with all_types.TestAllTypes.from_bytes(42) as msg:
pass
@pytest.mark.skipif( @pytest.mark.skipif(
@ -229,14 +233,14 @@ def test_from_bytes_traversal_limit(all_types):
bld.init("structList", size) bld.init("structList", size)
data = bld.to_bytes() data = bld.to_bytes()
msg = all_types.TestAllTypes.from_bytes(data) with all_types.TestAllTypes.from_bytes(data) as msg:
with pytest.raises(capnp.KjException): with pytest.raises(capnp.KjException):
for i in range(0, size): for i in range(0, size):
msg.structList[i].uInt8Field == 0 msg.structList[i].uInt8Field == 0
msg = all_types.TestAllTypes.from_bytes(data, traversal_limit_in_words=2 ** 62) with all_types.TestAllTypes.from_bytes(data, traversal_limit_in_words=2 ** 62) as msg:
for i in range(0, size): for i in range(0, size):
assert msg.structList[i].uInt8Field == 0 assert msg.structList[i].uInt8Field == 0
def test_from_bytes_packed_traversal_limit(all_types): def test_from_bytes_packed_traversal_limit(all_types):