/Lib/ctypes/test/test_repr.py

http://unladen-swallow.googlecode.com/ · Python · 29 lines · 22 code · 6 blank · 1 comment · 3 complexity · 5fcc34556f0c362741f1f787c926cb1b MD5 · raw file

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