summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index b3f21ea..49decac 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -678,6 +678,24 @@ class StructTest(unittest.TestCase):
'embedded null character'):
struct.calcsize(s)
+ @support.cpython_only
+ def test_issue45034_unsigned(self):
+ from _testcapi import USHRT_MAX
+ error_msg = f'ushort format requires 0 <= number <= {USHRT_MAX}'
+ with self.assertRaisesRegex(struct.error, error_msg):
+ struct.pack('H', 70000) # too large
+ with self.assertRaisesRegex(struct.error, error_msg):
+ struct.pack('H', -1) # too small
+
+ @support.cpython_only
+ def test_issue45034_signed(self):
+ from _testcapi import SHRT_MIN, SHRT_MAX
+ error_msg = f'short format requires {SHRT_MIN} <= number <= {SHRT_MAX}'
+ with self.assertRaisesRegex(struct.error, error_msg):
+ struct.pack('h', 70000) # too large
+ with self.assertRaisesRegex(struct.error, error_msg):
+ struct.pack('h', -70000) # too small
+
class UnpackIteratorTest(unittest.TestCase):
"""