diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2011-08-30 20:02:51 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2011-08-30 20:02:51 (GMT) |
commit | faecc3880971eb916c6769e443adfeca4d474218 (patch) | |
tree | b3b8fb2f28e89b11d94e52c34bf63df93ac10cda /Lib | |
parent | 326e189410106de22c4af9d8449e0a8dc631c7dc (diff) | |
download | cpython-faecc3880971eb916c6769e443adfeca4d474218.zip cpython-faecc3880971eb916c6769e443adfeca4d474218.tar.gz cpython-faecc3880971eb916c6769e443adfeca4d474218.tar.bz2 |
Issue #11241: subclasses of ctypes.Array can now be subclassed.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_arrays.py | 52 |
1 files changed, 52 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() |