Skip to content

bpo-23578: Show which offset raise error when using struct.pack #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,19 @@ def test_boundary_error_message_with_negative_offset(self):
'offset -11 out of range for 10-byte buffer'):
struct.pack_into('<B', byte_list, -11, 123)

def test_bad_value_error_message(self):
regex = (
r'got bad value at item 4, short format requires '
)
with self.assertRaisesRegex(struct.error, regex):
struct.pack('4h', 0x5FFF, 0x6FFF, 0x7FFF, 0x8FFF)
with self.assertRaisesRegex(struct.error, regex):
struct.pack('3hh', 0x5FFF, 0x6FFF, 0x7FFF, 0x8FFF)
with self.assertRaisesRegex(struct.error, regex):
struct.pack('hhhh', 0x5FFF, 0x6FFF, 0x7FFF, 0x8FFF)
with self.assertRaisesRegex(struct.error, regex):
struct.pack('iihh', 0x5FFF, 0x6FFF, 0x7FFF, 0x8FFF)

def test_issue29802(self):
# When the second argument of struct.unpack() was of wrong type
# the Struct object was decrefed twice and the reference to
Expand Down
Loading