mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 08:24:43 +01:00
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:
parent
4b75fe3b5e
commit
e2f3e5da46
1 changed files with 18 additions and 14 deletions
|
@ -46,7 +46,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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:
|
||||||
|
with all_types.TestAllTypes.from_bytes(v) as msg:
|
||||||
test_regression.check_all_types(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,12 +233,12 @@ 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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue