mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
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>
This commit is contained in:
parent
97b754d4b4
commit
8ca6b61e3f
4 changed files with 27 additions and 6 deletions
|
@ -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):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue