summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2021-09-07 12:18:46 (GMT)
committerGitHub <noreply@github.com>2021-09-07 12:18:46 (GMT)
commit8ca6b61e3fd7f1e2876126cee82da8d812c8462f (patch)
treed3f55761ad4c4cbac8db1814e5d11a0b7c24e7b2 /Lib/test
parent97b754d4b46ad9dd63f68906484f805931578c81 (diff)
downloadcpython-8ca6b61e3fd7f1e2876126cee82da8d812c8462f.zip
cpython-8ca6b61e3fd7f1e2876126cee82da8d812c8462f.tar.gz
cpython-8ca6b61e3fd7f1e2876126cee82da8d812c8462f.tar.bz2
bpo-45034: Fix how upper limit is formatted for `struct.pack("H", ...)` (GH-28178)
Co-authored-by: Mark Dickinson <dickinsm@gmail.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-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):
"""