mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
Fix up struct docstrings, add struct.pack_to function for symmetry
This commit is contained in:
parent
90bd0a554e
commit
1fcdc232db
3 changed files with 42 additions and 8 deletions
|
@ -509,6 +509,28 @@ class PackBufferTestCase(unittest.TestCase):
|
|||
self.assertRaises(struct.error, s.pack_to, small_buf, 0, test_string)
|
||||
self.assertRaises(struct.error, s.pack_to, small_buf, 2, test_string)
|
||||
|
||||
def test_pack_to_fn( self ):
|
||||
test_string = 'Reykjavik rocks, eow!'
|
||||
writable_buf = array.array('c', ' '*100)
|
||||
fmt = '21s'
|
||||
pack_to = lambda *args: struct.pack_to(fmt, *args)
|
||||
|
||||
# Test without offset
|
||||
pack_to(writable_buf, 0, test_string)
|
||||
from_buf = writable_buf.tostring()[:len(test_string)]
|
||||
self.assertEquals(from_buf, test_string)
|
||||
|
||||
# Test with offset.
|
||||
pack_to(writable_buf, 10, test_string)
|
||||
from_buf = writable_buf.tostring()[:len(test_string)+10]
|
||||
self.assertEquals(from_buf, (test_string[:10] + test_string))
|
||||
|
||||
# Go beyond boundaries.
|
||||
small_buf = array.array('c', ' '*10)
|
||||
self.assertRaises(struct.error, pack_to, small_buf, 0, test_string)
|
||||
self.assertRaises(struct.error, pack_to, small_buf, 2, test_string)
|
||||
|
||||
|
||||
def test_main():
|
||||
test.test_support.run_unittest(PackBufferTestCase)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue