summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2006-05-27 12:11:36 (GMT)
committerBob Ippolito <bob@redivi.com>2006-05-27 12:11:36 (GMT)
commit1fcdc232dbfbd05b92eaed42bf9f779d27c55a92 (patch)
tree9ab05c5be55ea37cca7723725491bb80a8498a21 /Lib/test/test_struct.py
parent90bd0a554eec9d55b1474f713834681d2646ff25 (diff)
downloadcpython-1fcdc232dbfbd05b92eaed42bf9f779d27c55a92.zip
cpython-1fcdc232dbfbd05b92eaed42bf9f779d27c55a92.tar.gz
cpython-1fcdc232dbfbd05b92eaed42bf9f779d27c55a92.tar.bz2
Fix up struct docstrings, add struct.pack_to function for symmetry
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 6bc1f86..7981a52 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -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)