Debian Codegraph @

pypy/module/struct/test/apptest_structbuffer.py

raw symbols SCIP
1 """
2 Tests for the struct module implemented at interp-level in pypy/module/struct.
3 """
4
5 # spaceconfig = {"usemodules": ["struct", "__pypy__"]}
6 import struct
7 from __pypy__ import bytebuffer
8
9 def test_pack_into():
10 b = bytebuffer(19)
11 sz = struct.calcsize("ii")
12 struct.pack_into("ii", b, 2, 17, 42)
13 assert b[:] == (b'\x00' * 2 +
14 struct.pack("ii", 17, 42) +
15 b'\x00' * (19-sz-2))
16 m = memoryview(b)
17 struct.pack_into("ii", m, 2, 17, 42)
18
19 def test_unpack_from():
20 b = bytebuffer(19)
21 sz = struct.calcsize("ii")
22 b[2:2+sz] = struct.pack("ii", 17, 42)
23 assert struct.unpack_from("ii", b, 2) == (17, 42)
24 b[:sz] = struct.pack("ii", 18, 43)
25 assert struct.unpack_from("ii", b) == (18, 43)