2014-02-07 04:06:05 -04:00
|
|
|
import unittest
|
|
|
|
from test import test_support
|
|
|
|
|
|
|
|
# Skip this test if the _testcapi module isn't available.
|
|
|
|
test_support.import_module('_testcapi')
|
2010-04-03 07:27:05 -03:00
|
|
|
from _testcapi import _test_structmembersType, \
|
2006-10-27 03:16:31 -03:00
|
|
|
CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
|
|
|
|
SHRT_MAX, SHRT_MIN, USHRT_MAX, \
|
|
|
|
INT_MAX, INT_MIN, UINT_MAX, \
|
2007-06-09 04:42:52 -03:00
|
|
|
LONG_MAX, LONG_MIN, ULONG_MAX, \
|
|
|
|
LLONG_MAX, LLONG_MIN, ULLONG_MAX
|
2006-10-27 03:16:31 -03:00
|
|
|
|
2010-04-03 07:27:05 -03:00
|
|
|
ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
|
2010-04-02 22:28:57 -03:00
|
|
|
9.99999, 10.1010101010, "hi")
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
class ReadWriteTests(unittest.TestCase):
|
2010-04-02 22:08:34 -03:00
|
|
|
|
|
|
|
def test_bool(self):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BOOL = True
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_BOOL, True)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BOOL = False
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_BOOL, False)
|
2008-01-21 17:23:15 -04:00
|
|
|
self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1)
|
|
|
|
|
2010-04-02 22:08:34 -03:00
|
|
|
def test_byte(self):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BYTE = CHAR_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_BYTE, CHAR_MAX)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BYTE = CHAR_MIN
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_BYTE, CHAR_MIN)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_UBYTE = UCHAR_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_UBYTE, UCHAR_MAX)
|
2006-10-27 03:16:31 -03:00
|
|
|
|
2010-04-02 22:08:34 -03:00
|
|
|
def test_short(self):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_SHORT = SHRT_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_SHORT, SHRT_MAX)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_SHORT = SHRT_MIN
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_SHORT, SHRT_MIN)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_USHORT = USHRT_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_USHORT, USHRT_MAX)
|
2006-10-27 03:16:31 -03:00
|
|
|
|
2010-04-02 22:08:34 -03:00
|
|
|
def test_int(self):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_INT = INT_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_INT, INT_MAX)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_INT = INT_MIN
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_INT, INT_MIN)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_UINT = UINT_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_UINT, UINT_MAX)
|
2006-10-27 03:16:31 -03:00
|
|
|
|
2010-04-02 22:08:34 -03:00
|
|
|
def test_long(self):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_LONG = LONG_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_LONG, LONG_MAX)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_LONG = LONG_MIN
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_LONG, LONG_MIN)
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_ULONG = ULONG_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_ULONG, ULONG_MAX)
|
2006-10-27 03:16:31 -03:00
|
|
|
|
2010-04-02 22:08:34 -03:00
|
|
|
@unittest.skipUnless(hasattr(ts, "T_LONGLONG"), "long long not present")
|
|
|
|
def test_longlong(self):
|
|
|
|
ts.T_LONGLONG = LLONG_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_LONGLONG, LLONG_MAX)
|
2010-04-02 22:08:34 -03:00
|
|
|
ts.T_LONGLONG = LLONG_MIN
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_LONGLONG, LLONG_MIN)
|
2010-04-02 22:08:34 -03:00
|
|
|
|
|
|
|
ts.T_ULONGLONG = ULLONG_MAX
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_ULONGLONG, ULLONG_MAX)
|
2010-04-02 22:08:34 -03:00
|
|
|
|
|
|
|
## make sure these will accept a plain int as well as a long
|
|
|
|
ts.T_LONGLONG = 3
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_LONGLONG, 3)
|
2010-04-02 22:08:34 -03:00
|
|
|
ts.T_ULONGLONG = 4
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_ULONGLONG, 4)
|
2007-06-09 04:42:52 -03:00
|
|
|
|
2010-04-02 22:28:57 -03:00
|
|
|
def test_inplace_string(self):
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(ts.T_STRING_INPLACE, "hi")
|
2010-04-02 22:28:57 -03:00
|
|
|
self.assertRaises(TypeError, setattr, ts, "T_STRING_INPLACE", "s")
|
|
|
|
self.assertRaises(TypeError, delattr, ts, "T_STRING_INPLACE")
|
|
|
|
|
2007-06-09 04:42:52 -03:00
|
|
|
|
2007-04-03 15:33:29 -03:00
|
|
|
class TestWarnings(unittest.TestCase):
|
2006-11-02 22:32:46 -04:00
|
|
|
|
2006-10-27 03:16:31 -03:00
|
|
|
def test_byte_max(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BYTE = CHAR_MAX+1
|
2006-11-02 22:32:46 -04:00
|
|
|
|
2006-10-27 03:16:31 -03:00
|
|
|
def test_byte_min(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_BYTE = CHAR_MIN-1
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
def test_ubyte_max(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_UBYTE = UCHAR_MAX+1
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
def test_short_max(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_SHORT = SHRT_MAX+1
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
def test_short_min(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_SHORT = SHRT_MIN-1
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
def test_ushort_max(self):
|
2010-03-17 16:15:56 -03:00
|
|
|
with test_support.check_warnings(('', RuntimeWarning)):
|
2008-01-21 17:28:32 -04:00
|
|
|
ts.T_USHORT = USHRT_MAX+1
|
2006-11-02 22:32:46 -04:00
|
|
|
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
def test_main(verbose=None):
|
2007-08-24 18:09:42 -03:00
|
|
|
test_support.run_unittest(__name__)
|
2006-10-27 03:16:31 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main(verbose=True)
|