ยปCore Development>Code coverage>Lib/ctypes/test/test_repr.py

Python code coverage for Lib/ctypes/test/test_repr.py

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