Skip to content

Commit 10a8149

Browse files
committed
Skip the mode-mix regression tests on the pure Python fallback
The fallback rolls its buffer position back to the last checkpoint on every OutOfData, so an incomplete read never leaves behind a stack frame the way the C extension does. Resuming with the other method just reparses the header from scratch and works fine there, so the ValueError the C extension raises for that mix isn't something the fallback needs to reproduce. Marked the two mix tests C-extension-only with the project's existing Packer.__module__ skipif convention, and added the fallback's own pair of tests confirming the mix still succeeds instead of silently going untested on that backend.
1 parent aaf38ec commit 10a8149

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

test/test_sequnpack.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import io
33

4+
import pytest
45
from pytest import raises
56

67
from msgpack import BufferFull, Unpacker, pack, packb
@@ -63,6 +64,10 @@ def test_foobar_skip():
6364
unpacker.unpack()
6465

6566

67+
@pytest.mark.skipif(
68+
Unpacker.__module__ == "msgpack.fallback",
69+
reason="only the C extension keeps a stack frame across an incomplete read",
70+
)
6671
def test_skip_then_unpack_across_incomplete_container():
6772
# skip() opens the array's stack frame without ever populating its
6873
# object slot (it has nothing to build), so resuming with unpack()
@@ -77,6 +82,10 @@ def test_skip_then_unpack_across_incomplete_container():
7782
unpacker.unpack()
7883

7984

85+
@pytest.mark.skipif(
86+
Unpacker.__module__ == "msgpack.fallback",
87+
reason="only the C extension keeps a stack frame across an incomplete read",
88+
)
8089
def test_unpack_then_skip_across_incomplete_container():
8190
unpacker = Unpacker()
8291
unpacker.feed(b"\x91")
@@ -105,6 +114,37 @@ def test_unpack_then_unpack_across_incomplete_container_still_works():
105114
assert unpacker.unpack() == [0]
106115

107116

117+
@pytest.mark.skipif(
118+
Unpacker.__module__ != "msgpack.fallback",
119+
reason="the C extension is the one that needs to reject this mix, see the tests above",
120+
)
121+
def test_fallback_skip_then_unpack_across_incomplete_container_still_works():
122+
# The fallback never keeps a stack frame across an OutOfData; an
123+
# incomplete read rolls the buffer position back to where the call
124+
# started, so the next call just reparses the array header from
125+
# scratch regardless of which method it uses. No corruption risk here,
126+
# so unlike the C extension it doesn't need to reject the mix.
127+
unpacker = Unpacker()
128+
unpacker.feed(b"\x91")
129+
with raises(OutOfData):
130+
unpacker.skip()
131+
unpacker.feed(b"\x00")
132+
assert unpacker.unpack() == [0]
133+
134+
135+
@pytest.mark.skipif(
136+
Unpacker.__module__ != "msgpack.fallback",
137+
reason="the C extension is the one that needs to reject this mix, see the tests above",
138+
)
139+
def test_fallback_unpack_then_skip_across_incomplete_container_still_works():
140+
unpacker = Unpacker()
141+
unpacker.feed(b"\x91")
142+
with raises(OutOfData):
143+
unpacker.unpack()
144+
unpacker.feed(b"\x00")
145+
assert unpacker.skip() is None
146+
147+
108148
def test_maxbuffersize():
109149
with raises(ValueError):
110150
Unpacker(read_size=5, max_buffer_size=3)

0 commit comments

Comments
 (0)