Debian Codegraph @

lib-python/3/ctypes/test/test_repr.py

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