move sections
[python/dscho.git] / Lib / test / test_structmembers.py
blobff1711c73b4c1d012252d4d361e0e670cfc82852
1 from _testcapi import _test_structmembersType, \
2 CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
3 SHRT_MAX, SHRT_MIN, USHRT_MAX, \
4 INT_MAX, INT_MIN, UINT_MAX, \
5 LONG_MAX, LONG_MIN, ULONG_MAX, \
6 LLONG_MAX, LLONG_MIN, ULLONG_MAX
8 import unittest
9 from test import test_support
11 ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
12 9.99999, 10.1010101010, "hi")
14 class ReadWriteTests(unittest.TestCase):
16 def test_bool(self):
17 ts.T_BOOL = True
18 self.assertEquals(ts.T_BOOL, True)
19 ts.T_BOOL = False
20 self.assertEquals(ts.T_BOOL, False)
21 self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1)
23 def test_byte(self):
24 ts.T_BYTE = CHAR_MAX
25 self.assertEquals(ts.T_BYTE, CHAR_MAX)
26 ts.T_BYTE = CHAR_MIN
27 self.assertEquals(ts.T_BYTE, CHAR_MIN)
28 ts.T_UBYTE = UCHAR_MAX
29 self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
31 def test_short(self):
32 ts.T_SHORT = SHRT_MAX
33 self.assertEquals(ts.T_SHORT, SHRT_MAX)
34 ts.T_SHORT = SHRT_MIN
35 self.assertEquals(ts.T_SHORT, SHRT_MIN)
36 ts.T_USHORT = USHRT_MAX
37 self.assertEquals(ts.T_USHORT, USHRT_MAX)
39 def test_int(self):
40 ts.T_INT = INT_MAX
41 self.assertEquals(ts.T_INT, INT_MAX)
42 ts.T_INT = INT_MIN
43 self.assertEquals(ts.T_INT, INT_MIN)
44 ts.T_UINT = UINT_MAX
45 self.assertEquals(ts.T_UINT, UINT_MAX)
47 def test_long(self):
48 ts.T_LONG = LONG_MAX
49 self.assertEquals(ts.T_LONG, LONG_MAX)
50 ts.T_LONG = LONG_MIN
51 self.assertEquals(ts.T_LONG, LONG_MIN)
52 ts.T_ULONG = ULONG_MAX
53 self.assertEquals(ts.T_ULONG, ULONG_MAX)
55 @unittest.skipUnless(hasattr(ts, "T_LONGLONG"), "long long not present")
56 def test_longlong(self):
57 ts.T_LONGLONG = LLONG_MAX
58 self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
59 ts.T_LONGLONG = LLONG_MIN
60 self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
62 ts.T_ULONGLONG = ULLONG_MAX
63 self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
65 ## make sure these will accept a plain int as well as a long
66 ts.T_LONGLONG = 3
67 self.assertEquals(ts.T_LONGLONG, 3)
68 ts.T_ULONGLONG = 4
69 self.assertEquals(ts.T_ULONGLONG, 4)
71 def test_inplace_string(self):
72 self.assertEquals(ts.T_STRING_INPLACE, "hi")
73 self.assertRaises(TypeError, setattr, ts, "T_STRING_INPLACE", "s")
74 self.assertRaises(TypeError, delattr, ts, "T_STRING_INPLACE")
77 class TestWarnings(unittest.TestCase):
79 def test_byte_max(self):
80 with test_support.check_warnings(('', RuntimeWarning)):
81 ts.T_BYTE = CHAR_MAX+1
83 def test_byte_min(self):
84 with test_support.check_warnings(('', RuntimeWarning)):
85 ts.T_BYTE = CHAR_MIN-1
87 def test_ubyte_max(self):
88 with test_support.check_warnings(('', RuntimeWarning)):
89 ts.T_UBYTE = UCHAR_MAX+1
91 def test_short_max(self):
92 with test_support.check_warnings(('', RuntimeWarning)):
93 ts.T_SHORT = SHRT_MAX+1
95 def test_short_min(self):
96 with test_support.check_warnings(('', RuntimeWarning)):
97 ts.T_SHORT = SHRT_MIN-1
99 def test_ushort_max(self):
100 with test_support.check_warnings(('', RuntimeWarning)):
101 ts.T_USHORT = USHRT_MAX+1
104 def test_main(verbose=None):
105 test_support.run_unittest(__name__)
107 if __name__ == "__main__":
108 test_main(verbose=True)