| 1 |
import unittest |
| 2 |
from ctypes import (c_byte, c_short, c_int, c_long, c_longlong, |
| 3 |
c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong, |
| 4 |
c_float, c_double, c_longdouble, c_bool, c_char) |
| 5 |
|
| 6 |
|
| 7 |
subclasses = [] |
| 8 |
for base in [c_byte, c_short, c_int, c_long, c_longlong, |
| 9 |
c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong, |
| 10 |
c_float, c_double, c_longdouble, c_bool]: |
| 11 |
class X(base): |
| 12 |
pass |
| 13 |
subclasses.append(X) |
| 14 |
|
| 15 |
|
| 16 |
class X(c_char): |
| 17 |
pass |
| 18 |
|
| 19 |
|
| 20 |
# This test checks if the __repr__ is correct for subclasses of simple types |
| 21 |
class ReprTest(unittest.TestCase): |
| 22 |
def test_numbers(self): |
| 23 |
for typ in subclasses: |
| 24 |
base = typ.__bases__[0] |
| 25 |
self.assertStartsWith(repr(base(42)), base.__name__) |
| 26 |
self.assertStartsWith(repr(typ(42)), "<X object at") |
| 27 |
|
| 28 |
def test_char(self): |
| 29 |
self.assertEqual("c_char(b'x')", repr(c_char(b'x'))) |
| 30 |
self.assertStartsWith(repr(X(b'x')), "<X object at") |
| 31 |
|
| 32 |
|
| 33 |
if __name__ == "__main__": |
| 34 |
unittest.main() |