PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/Lib/ctypes/test/test_repr.py

http://unladen-swallow.googlecode.com/
Python | 29 lines | 22 code | 6 blank | 1 comment | 5 complexity | 5fcc34556f0c362741f1f787c926cb1b MD5 | raw file
 1from ctypes import *
 2import unittest
 3
 4subclasses = []
 5for 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
12class X(c_char):
13    pass
14
15# This test checks if the __repr__ is correct for subclasses of simple types
16
17class ReprTest(unittest.TestCase):
18    def test_numbers(self):
19        for typ in subclasses:
20            base = typ.__bases__[0]
21            self.failUnless(repr(base(42)).startswith(base.__name__))
22            self.failUnlessEqual("<X object at", repr(typ(42))[:12])
23
24    def test_char(self):
25        self.failUnlessEqual("c_char('x')", repr(c_char('x')))
26        self.failUnlessEqual("<X object at", repr(X('x'))[:12])
27
28if __name__ == "__main__":
29    unittest.main()