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