Skip to content

Commit 219b7df

Browse files
committed
add test
1 parent d33514b commit 219b7df

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_struct.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,24 @@ def test_c_complex_round_trip(self):
800800
round_trip = struct.unpack(f, struct.pack(f, z))[0]
801801
self.assertComplexesAreIdentical(z, round_trip)
802802

803+
def test_endian_table_init_subinterpreters(self):
804+
# Verify that struct works correctly in subinterpreters after
805+
# once-only endian table initialization (gh-140260).
806+
# Use struct in the main interpreter first.
807+
self.assertEqual(struct.unpack('>i', struct.pack('>i', 1))[0], 1)
808+
self.assertEqual(struct.unpack('<i', struct.pack('<i', 1))[0], 1)
809+
810+
code = (
811+
"import struct\n"
812+
"x = struct.pack('>i', 1)\n"
813+
"assert struct.unpack('>i', x)[0] == 1\n"
814+
"y = struct.pack('<i', 1)\n"
815+
"assert struct.unpack('<i', y)[0] == 1\n"
816+
)
817+
for _ in range(3):
818+
ret = support.run_in_subinterp(code)
819+
self.assertEqual(ret, 0)
820+
803821

804822
class UnpackIteratorTest(unittest.TestCase):
805823
"""

0 commit comments

Comments
 (0)