summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-04-03 15:54:36 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-04-03 15:54:36 (GMT)
commitc593577a4a90b9c806c744b151efcb4e6b052aa4 (patch)
treec88828d3c2cb1fd0925f2058cfaf3063edd289c2 /Lib
parent089b00cbc3006fa60fe71f64341e38b83cc4498d (diff)
downloadcpython-c593577a4a90b9c806c744b151efcb4e6b052aa4.zip
cpython-c593577a4a90b9c806c744b151efcb4e6b052aa4.tar.gz
cpython-c593577a4a90b9c806c744b151efcb4e6b052aa4.tar.bz2
Merged revisions 79674 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79674 | mark.dickinson | 2010-04-03 15:05:10 +0100 (Sat, 03 Apr 2010) | 3 lines Issue #8300: Let struct.pack use __index__ to convert and pack non-integers. Based on a patch by Meador Inge. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_struct.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 39ccb27..3d67abd 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -282,6 +282,23 @@ class StructTest(unittest.TestCase):
struct.pack, self.format,
NotAnInt)
+ # Objects with an '__index__' method should be allowed
+ # to pack as integers.
+ class Indexable(object):
+ def __init__(self, value):
+ self._value = value
+
+ def __index__(self):
+ return self._value
+
+ for obj in (Indexable(0), Indexable(10), Indexable(17),
+ Indexable(42), Indexable(100), Indexable(127)):
+ try:
+ struct.pack(format, obj)
+ except:
+ self.fail("integer code pack failed on object "
+ "with '__index__' method")
+
for code in integer_codes:
for byteorder in byteorders:
if (byteorder in ('', '@') and code in ('q', 'Q') and