summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2011-08-30 20:07:20 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2011-08-30 20:07:20 (GMT)
commitdd2f8b0b776bdc0ad062f183403aa1b5a2629d39 (patch)
tree9f147bcdda18773a0a45c8da58d4ecc1155057c5 /Lib/ctypes
parent7a18d21230b4efb203a9a2ce9972962a2bf8fe04 (diff)
parentfaecc3880971eb916c6769e443adfeca4d474218 (diff)
downloadcpython-dd2f8b0b776bdc0ad062f183403aa1b5a2629d39.zip
cpython-dd2f8b0b776bdc0ad062f183403aa1b5a2629d39.tar.gz
cpython-dd2f8b0b776bdc0ad062f183403aa1b5a2629d39.tar.bz2
Merge from 3.2:
- Issue #9651: Fix a crash when ctypes.create_string_buffer(0) was passed to file.write() - Issue #11241: subclasses of ctypes.Array can now be subclassed.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/test/test_arrays.py52
-rw-r--r--Lib/ctypes/test/test_buffers.py4
2 files changed, 56 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_arrays.py b/Lib/ctypes/test/test_arrays.py
index f2a9f07..cfc219e 100644
--- a/Lib/ctypes/test/test_arrays.py
+++ b/Lib/ctypes/test/test_arrays.py
@@ -127,5 +127,57 @@ class ArrayTestCase(unittest.TestCase):
t2 = my_int * 1
self.assertTrue(t1 is t2)
+ def test_subclass(self):
+ class T(Array):
+ _type_ = c_int
+ _length_ = 13
+ class U(T):
+ pass
+ class V(U):
+ pass
+ class W(V):
+ pass
+ class X(T):
+ _type_ = c_short
+ class Y(T):
+ _length_ = 187
+
+ for c in [T, U, V, W]:
+ self.assertEqual(c._type_, c_int)
+ self.assertEqual(c._length_, 13)
+ self.assertEqual(c()._type_, c_int)
+ self.assertEqual(c()._length_, 13)
+
+ self.assertEqual(X._type_, c_short)
+ self.assertEqual(X._length_, 13)
+ self.assertEqual(X()._type_, c_short)
+ self.assertEqual(X()._length_, 13)
+
+ self.assertEqual(Y._type_, c_int)
+ self.assertEqual(Y._length_, 187)
+ self.assertEqual(Y()._type_, c_int)
+ self.assertEqual(Y()._length_, 187)
+
+ def test_bad_subclass(self):
+ import sys
+
+ with self.assertRaises(AttributeError):
+ class T(Array):
+ pass
+ with self.assertRaises(AttributeError):
+ class T(Array):
+ _type_ = c_int
+ with self.assertRaises(AttributeError):
+ class T(Array):
+ _length_ = 13
+ with self.assertRaises(OverflowError):
+ class T(Array):
+ _type_ = c_int
+ _length_ = sys.maxsize * 2
+ with self.assertRaises(AttributeError):
+ class T(Array):
+ _type_ = c_int
+ _length_ = 1.87
+
if __name__ == '__main__':
unittest.main()
diff --git a/Lib/ctypes/test/test_buffers.py b/Lib/ctypes/test/test_buffers.py
index c19c05a..2dc7484 100644
--- a/Lib/ctypes/test/test_buffers.py
+++ b/Lib/ctypes/test/test_buffers.py
@@ -20,6 +20,10 @@ class StringBufferTestCase(unittest.TestCase):
self.assertEqual(b[::2], b"ac")
self.assertEqual(b[::5], b"a")
+ def test_buffer_interface(self):
+ self.assertEqual(len(bytearray(create_string_buffer(0))), 0)
+ self.assertEqual(len(bytearray(create_string_buffer(1))), 1)
+
try:
c_wchar
except NameError: