Require implementations for warnings.showwarning() support the 'line' argument.
[python.git] / Lib / test / test_structmembers.py
blobc196cc5147483081ff044cceff135a7ded0c0571
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 warnings, exceptions, unittest, sys
9 from test import test_support
11 ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
12 9.99999, 10.1010101010)
14 class ReadWriteTests(unittest.TestCase):
15 def test_types(self):
16 ts.T_BOOL = True
17 self.assertEquals(ts.T_BOOL, True)
18 ts.T_BOOL = False
19 self.assertEquals(ts.T_BOOL, False)
20 self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1)
22 ts.T_BYTE = CHAR_MAX
23 self.assertEquals(ts.T_BYTE, CHAR_MAX)
24 ts.T_BYTE = CHAR_MIN
25 self.assertEquals(ts.T_BYTE, CHAR_MIN)
26 ts.T_UBYTE = UCHAR_MAX
27 self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
29 ts.T_SHORT = SHRT_MAX
30 self.assertEquals(ts.T_SHORT, SHRT_MAX)
31 ts.T_SHORT = SHRT_MIN
32 self.assertEquals(ts.T_SHORT, SHRT_MIN)
33 ts.T_USHORT = USHRT_MAX
34 self.assertEquals(ts.T_USHORT, USHRT_MAX)
36 ts.T_INT = INT_MAX
37 self.assertEquals(ts.T_INT, INT_MAX)
38 ts.T_INT = INT_MIN
39 self.assertEquals(ts.T_INT, INT_MIN)
40 ts.T_UINT = UINT_MAX
41 self.assertEquals(ts.T_UINT, UINT_MAX)
43 ts.T_LONG = LONG_MAX
44 self.assertEquals(ts.T_LONG, LONG_MAX)
45 ts.T_LONG = LONG_MIN
46 self.assertEquals(ts.T_LONG, LONG_MIN)
47 ts.T_ULONG = ULONG_MAX
48 self.assertEquals(ts.T_ULONG, ULONG_MAX)
50 ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
51 if hasattr(ts, 'T_LONGLONG'):
52 ts.T_LONGLONG = LLONG_MAX
53 self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
54 ts.T_LONGLONG = LLONG_MIN
55 self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
57 ts.T_ULONGLONG = ULLONG_MAX
58 self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
60 ## make sure these will accept a plain int as well as a long
61 ts.T_LONGLONG = 3
62 self.assertEquals(ts.T_LONGLONG, 3)
63 ts.T_ULONGLONG = 4
64 self.assertEquals(ts.T_ULONGLONG, 4)
67 class TestWarnings(unittest.TestCase):
68 def has_warned(self, w):
69 self.assertEqual(w.category, RuntimeWarning)
71 def test_byte_max(self):
72 with test_support.check_warnings() as w:
73 ts.T_BYTE = CHAR_MAX+1
74 self.has_warned(w)
76 def test_byte_min(self):
77 with test_support.check_warnings() as w:
78 ts.T_BYTE = CHAR_MIN-1
79 self.has_warned(w)
81 def test_ubyte_max(self):
82 with test_support.check_warnings() as w:
83 ts.T_UBYTE = UCHAR_MAX+1
84 self.has_warned(w)
86 def test_short_max(self):
87 with test_support.check_warnings() as w:
88 ts.T_SHORT = SHRT_MAX+1
89 self.has_warned(w)
91 def test_short_min(self):
92 with test_support.check_warnings() as w:
93 ts.T_SHORT = SHRT_MIN-1
94 self.has_warned(w)
96 def test_ushort_max(self):
97 with test_support.check_warnings() as w:
98 ts.T_USHORT = USHRT_MAX+1
99 self.has_warned(w)
103 def test_main(verbose=None):
104 test_support.run_unittest(__name__)
106 if __name__ == "__main__":
107 test_main(verbose=True)