mirror of
https://github.com/python/cpython.git
synced 2025-09-05 00:11:10 +00:00
Issue #3129: Trailing digits in format string are no longer ignored.
This commit is contained in:
parent
9b88b916a9
commit
177e8530cb
3 changed files with 36 additions and 3 deletions
|
@ -443,7 +443,7 @@ class StructTest(unittest.TestCase):
|
|||
|
||||
# Test bogus offset (issue 3694)
|
||||
sb = small_buf
|
||||
self.assertRaises(TypeError, struct.pack_into, b'1', sb, None)
|
||||
self.assertRaises(TypeError, struct.pack_into, b'', sb, None)
|
||||
|
||||
def test_pack_into_fn(self):
|
||||
test_string = b'Reykjavik rocks, eow!'
|
||||
|
@ -510,6 +510,32 @@ class StructTest(unittest.TestCase):
|
|||
def test_crasher(self):
|
||||
self.assertRaises(MemoryError, struct.pack, "357913941b", "a")
|
||||
|
||||
def test_trailing_counter(self):
|
||||
store = array.array('b', b' '*100)
|
||||
|
||||
# format lists containing only count spec should result in an error
|
||||
self.assertRaises(struct.error, struct.pack, '12345')
|
||||
self.assertRaises(struct.error, struct.unpack, '12345', '')
|
||||
self.assertRaises(struct.error, struct.pack_into, '12345', store, 0)
|
||||
self.assertRaises(struct.error, struct.unpack_from, '12345', store, 0)
|
||||
|
||||
# Format lists with trailing count spec should result in an error
|
||||
self.assertRaises(struct.error, struct.pack, 'c12345', 'x')
|
||||
self.assertRaises(struct.error, struct.unpack, 'c12345', 'x')
|
||||
self.assertRaises(struct.error, struct.pack_into, 'c12345', store, 0,
|
||||
'x')
|
||||
self.assertRaises(struct.error, struct.unpack_from, 'c12345', store,
|
||||
0)
|
||||
|
||||
# Mixed format tests
|
||||
self.assertRaises(struct.error, struct.pack, '14s42', 'spam and eggs')
|
||||
self.assertRaises(struct.error, struct.unpack, '14s42',
|
||||
'spam and eggs')
|
||||
self.assertRaises(struct.error, struct.pack_into, '14s42', store, 0,
|
||||
'spam and eggs')
|
||||
self.assertRaises(struct.error, struct.unpack_from, '14s42', store, 0)
|
||||
|
||||
|
||||
|
||||
def test_main():
|
||||
run_unittest(StructTest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue