MCPcopy Index your code
hub / github.com/python/mypy / test_struct_offsets

Method test_struct_offsets

mypyc/test/test_struct.py:17–48  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

15
16class TestStruct(unittest.TestCase):
17 def test_struct_offsets(self) -> None:
18 # test per-member alignment
19 r = RStruct("", [], [bool_rprimitive, int32_rprimitive, int64_rprimitive])
20 assert r.size == 16
21 assert r.offsets == [0, 4, 8]
22
23 # test final alignment
24 r1 = RStruct("", [], [bool_rprimitive, bool_rprimitive])
25 assert r1.size == 2
26 assert r1.offsets == [0, 1]
27 r2 = RStruct("", [], [int32_rprimitive, bool_rprimitive])
28 r3 = RStruct("", [], [int64_rprimitive, bool_rprimitive])
29 assert r2.offsets == [0, 4]
30 assert r3.offsets == [0, 8]
31 assert r2.size == 8
32 assert r3.size == 16
33
34 r4 = RStruct("", [], [bool_rprimitive, bool_rprimitive, bool_rprimitive, int32_rprimitive])
35 assert r4.size == 8
36 assert r4.offsets == [0, 1, 2, 4]
37
38 # test nested struct
39 r5 = RStruct("", [], [bool_rprimitive, r])
40 assert r5.offsets == [0, 8]
41 assert r5.size == 24
42 r6 = RStruct("", [], [int32_rprimitive, r5])
43 assert r6.offsets == [0, 8]
44 assert r6.size == 32
45 # test nested struct with alignment less than 8
46 r7 = RStruct("", [], [bool_rprimitive, r4])
47 assert r7.offsets == [0, 4]
48 assert r7.size == 12
49
50 def test_struct_str(self) -> None:
51 r = RStruct("Foo", ["a", "b"], [bool_rprimitive, object_rprimitive])

Callers

nothing calls this directly

Calls 1

RStructClass · 0.90

Tested by

no test coverage detected