From da8f8869fc231d3a624e7893632af75dda1356d6 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Thu, 31 Jan 2019 01:02:11 -0800 Subject: [PATCH] Add some edge case tests for `read_multiple_bytes` --- test/test_large_read.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_large_read.py b/test/test_large_read.py index bb1129e..e912008 100644 --- a/test/test_large_read.py +++ b/test/test_large_read.py @@ -56,14 +56,44 @@ def test_large_read_multiple_bytes(test_capnp): for m in test_capnp.Msg.read_multiple_bytes(data): pass + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp)[:-1] + for m in test_capnp.Msg.read_multiple_bytes(data): + pass + + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp) + b' ' + for m in test_capnp.Msg.read_multiple_bytes(data): + pass + @pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason="PyPy memoryview support is limited") def test_large_read_mutltiple_bytes_memoryview(test_capnp): data = get_two_adjacent_messages(test_capnp) for m in test_capnp.Msg.read_multiple_bytes(memoryview(data)): pass + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp)[:-1] + for m in test_capnp.Msg.read_multiple_bytes(memoryview(data)): + pass + + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp) + b' ' + for m in test_capnp.Msg.read_multiple_bytes(memoryview(data)): + pass + @pytest.mark.skipif(sys.version_info[0] == 3, reason="Legacy buffer support only for python 2.7") def test_large_read_mutltiple_bytes_buffer(test_capnp): data = get_two_adjacent_messages(test_capnp) for m in test_capnp.Msg.read_multiple_bytes(buffer(data)): pass + + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp)[:-1] + for m in test_capnp.Msg.read_multiple_bytes(buffer(data)): + pass + + with pytest.raises(capnp.KjException): + data = get_two_adjacent_messages(test_capnp) + b' ' + for m in test_capnp.Msg.read_multiple_bytes(buffer(data)): + pass