blob: 27b4b7060a0f89246e2b748ba4d6206e295f5960 [file] [log] [blame]
Thomas Wouters89f507f2006-12-13 04:49:30 +00001from _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, \
Guido van Rossumcd16bf62007-06-13 18:07:49 +00005 LONG_MAX, LONG_MIN, ULONG_MAX, \
6 LLONG_MAX, LLONG_MIN, ULLONG_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +00007
Thomas Woutersed03b412007-08-28 21:37:11 +00008import warnings, unittest, sys
Thomas Wouters89f507f2006-12-13 04:49:30 +00009from test import test_support
10
Christian Heimes1af737c2008-01-23 08:24:23 +000011ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
12 9.99999, 10.1010101010)
Thomas Wouters89f507f2006-12-13 04:49:30 +000013
14class ReadWriteTests(unittest.TestCase):
15 def test_types(self):
Christian Heimes1af737c2008-01-23 08:24:23 +000016 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)
21
22 ts.T_BYTE = CHAR_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000023 self.assertEquals(ts.T_BYTE, CHAR_MAX)
Christian Heimes1af737c2008-01-23 08:24:23 +000024 ts.T_BYTE = CHAR_MIN
Thomas Wouters89f507f2006-12-13 04:49:30 +000025 self.assertEquals(ts.T_BYTE, CHAR_MIN)
Christian Heimes1af737c2008-01-23 08:24:23 +000026 ts.T_UBYTE = UCHAR_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000027 self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
28
Christian Heimes1af737c2008-01-23 08:24:23 +000029 ts.T_SHORT = SHRT_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000030 self.assertEquals(ts.T_SHORT, SHRT_MAX)
Christian Heimes1af737c2008-01-23 08:24:23 +000031 ts.T_SHORT = SHRT_MIN
Thomas Wouters89f507f2006-12-13 04:49:30 +000032 self.assertEquals(ts.T_SHORT, SHRT_MIN)
Christian Heimes1af737c2008-01-23 08:24:23 +000033 ts.T_USHORT = USHRT_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000034 self.assertEquals(ts.T_USHORT, USHRT_MAX)
35
Christian Heimes1af737c2008-01-23 08:24:23 +000036 ts.T_INT = INT_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000037 self.assertEquals(ts.T_INT, INT_MAX)
Christian Heimes1af737c2008-01-23 08:24:23 +000038 ts.T_INT = INT_MIN
Thomas Wouters89f507f2006-12-13 04:49:30 +000039 self.assertEquals(ts.T_INT, INT_MIN)
Christian Heimes1af737c2008-01-23 08:24:23 +000040 ts.T_UINT = UINT_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000041 self.assertEquals(ts.T_UINT, UINT_MAX)
42
Christian Heimes1af737c2008-01-23 08:24:23 +000043 ts.T_LONG = LONG_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000044 self.assertEquals(ts.T_LONG, LONG_MAX)
Christian Heimes1af737c2008-01-23 08:24:23 +000045 ts.T_LONG = LONG_MIN
Thomas Wouters89f507f2006-12-13 04:49:30 +000046 self.assertEquals(ts.T_LONG, LONG_MIN)
Christian Heimes1af737c2008-01-23 08:24:23 +000047 ts.T_ULONG = ULONG_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +000048 self.assertEquals(ts.T_ULONG, ULONG_MAX)
49
Guido van Rossumcd16bf62007-06-13 18:07:49 +000050 ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
51 if hasattr(ts, 'T_LONGLONG'):
Christian Heimes1af737c2008-01-23 08:24:23 +000052 ts.T_LONGLONG = LLONG_MAX
Guido van Rossumcd16bf62007-06-13 18:07:49 +000053 self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
Christian Heimes1af737c2008-01-23 08:24:23 +000054 ts.T_LONGLONG = LLONG_MIN
Guido van Rossumcd16bf62007-06-13 18:07:49 +000055 self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
56
Christian Heimes1af737c2008-01-23 08:24:23 +000057 ts.T_ULONGLONG = ULLONG_MAX
Guido van Rossumcd16bf62007-06-13 18:07:49 +000058 self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
59
60 ## make sure these will accept a plain int as well as a long
Christian Heimes1af737c2008-01-23 08:24:23 +000061 ts.T_LONGLONG = 3
Guido van Rossumcd16bf62007-06-13 18:07:49 +000062 self.assertEquals(ts.T_LONGLONG, 3)
Christian Heimes1af737c2008-01-23 08:24:23 +000063 ts.T_ULONGLONG = 4
Guido van Rossumcd16bf62007-06-13 18:07:49 +000064 self.assertEquals(ts.T_ULONGLONG, 4)
65
66
Guido van Rossumd8faa362007-04-27 19:54:29 +000067class TestWarnings(unittest.TestCase):
68 def has_warned(self, w):
Thomas Woutersed03b412007-08-28 21:37:11 +000069 self.assertEqual(w.category, RuntimeWarning)
Thomas Wouters89f507f2006-12-13 04:49:30 +000070
71 def test_byte_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000072 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000073 ts.T_BYTE = CHAR_MAX+1
Guido van Rossumd8faa362007-04-27 19:54:29 +000074 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000075
76 def test_byte_min(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000077 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000078 ts.T_BYTE = CHAR_MIN-1
Guido van Rossumd8faa362007-04-27 19:54:29 +000079 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000080
81 def test_ubyte_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000082 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000083 ts.T_UBYTE = UCHAR_MAX+1
Guido van Rossumd8faa362007-04-27 19:54:29 +000084 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000085
86 def test_short_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000087 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000088 ts.T_SHORT = SHRT_MAX+1
Guido van Rossumd8faa362007-04-27 19:54:29 +000089 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000090
91 def test_short_min(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000092 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000093 ts.T_SHORT = SHRT_MIN-1
Guido van Rossumd8faa362007-04-27 19:54:29 +000094 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000095
96 def test_ushort_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000097 with test_support.catch_warning() as w:
Christian Heimes1af737c2008-01-23 08:24:23 +000098 ts.T_USHORT = USHRT_MAX+1
Guido van Rossumd8faa362007-04-27 19:54:29 +000099 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000100
101
102
103def test_main(verbose=None):
Thomas Woutersed03b412007-08-28 21:37:11 +0000104 # Obscure hack so that this test passes after reloads or repeated calls
105 # to test_main (regrtest -R).
106 if '__warningregistry__' in globals():
107 del globals()['__warningregistry__']
108 if hasattr(sys, '__warningregistry__'):
109 del sys.__warningregistry__
110 test_support.run_unittest(__name__)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000111
112if __name__ == "__main__":
113 test_main(verbose=True)