Skip to content

Commit 7164328

Browse files
committed
fixes and coverage
1 parent 23b61d5 commit 7164328

2 files changed

Lines changed: 25 additions & 24 deletions

File tree

src/msgpack_stream/_msgpack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def pack_stream(stream, obj):
114114
if sl <= 0x1F:
115115
stream.write(_B[0xA0 | sl])
116116
elif sl <= 0xFF:
117-
stream.write(b"\xd9")
117+
stream.write(b"\xd9" + _B[sl])
118118
elif sl <= 0xFF_FF:
119-
stream.write(b"\xda")
119+
stream.write(b"\xda" + u16_b_pack(sl))
120120
elif sl <= 0xFF_FF_FF_FF:
121-
stream.write(b"\xdb")
121+
stream.write(b"\xdb" + u32_b_pack(sl))
122122
else:
123123
raise ValueError("str too large", obj)
124124
stream.write(s)

tests/test_conformance.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,40 @@
77
obj = {
88
b"bytearray": b"\x00\x01\x02\x03\x04",
99
"string": "🐍",
10-
"list": [0, 1.0, None, "", b"", True, {}],
10+
"list": [0, 1.0, None, "", b"", True, {}, {f"{i}": i for i in range(0x10000)}],
1111
"int": -1,
1212
"uint": 1,
1313
"float": 3.1416,
1414
"none": None,
1515
"boolean": True,
16-
"test": [],
16+
"test": [
17+
[
18+
power_of_2,
19+
power_of_2 - 1,
20+
power_of_2 + 1,
21+
-power_of_2,
22+
-(power_of_2 - 1),
23+
]
24+
for i in range(64)
25+
if (power_of_2 := 2**i)
26+
],
1727
}
1828

1929
obj["object"] = copy.deepcopy(obj)
2030

2131

22-
obj_extra = {None: None, 3: 3, -1: -1, True: True, False: "hey", 1.1: 1.1}
32+
obj["list_b1"] = [1] * 0x10
33+
obj["list_b2"] = [1] * 0x1_00_00
2334

24-
for i in range(64):
25-
li = obj["test"]
26-
pow2 = 2**i
27-
pow21 = pow2 - 1
28-
pow211 = pow2 + 1
29-
li.extend(
30-
[
31-
pow2,
32-
pow21,
33-
pow211,
34-
-pow2,
35-
-pow21,
36-
]
37-
)
38-
li.append(2**64 - 1)
39-
li.append(-(2**63))
35+
obj["str_b1"] = "a" * 0x20
36+
obj["str_b2"] = "a" * 0x1_00
37+
obj["str_b3"] = "a" * 0x1_00_00
38+
39+
obj["bytes_b1"] = b"a" * 0x1_00
40+
obj["bytes_b2"] = b"a" * 0x1_00_00
4041

41-
for i in range(2**18):
42-
obj[f"test{i}"] = i
42+
43+
obj_extra = {None: None, 3: 3, -1: -1, True: True, False: "hey", 1.1: 1.1}
4344

4445

4546
def test_conformance():

0 commit comments

Comments
 (0)