aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_structmembers.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_structmembers.py')
-rw-r--r--Lib/test/test_structmembers.py61
1 files changed, 49 insertions, 12 deletions
diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py
index 0cc58c3c728..18fecc38290 100644
--- a/Lib/test/test_structmembers.py
+++ b/Lib/test/test_structmembers.py
@@ -3,13 +3,26 @@ from _testcapi import _test_structmembersType, \
SHRT_MAX, SHRT_MIN, USHRT_MAX, \
INT_MAX, INT_MIN, UINT_MAX, \
LONG_MAX, LONG_MIN, ULONG_MAX, \
- LLONG_MAX, LLONG_MIN, ULLONG_MAX
+ LLONG_MAX, LLONG_MIN, ULLONG_MAX, \
+ PY_SSIZE_T_MAX, PY_SSIZE_T_MIN
import unittest
-from test import test_support
-
-ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
- 9.99999, 10.1010101010, "hi")
+from test import support
+
+ts=_test_structmembersType(False, # T_BOOL
+ 1, # T_BYTE
+ 2, # T_UBYTE
+ 3, # T_SHORT
+ 4, # T_USHORT
+ 5, # T_INT
+ 6, # T_UINT
+ 7, # T_LONG
+ 8, # T_ULONG
+ 23, # T_PYSSIZET
+ 9.99999,# T_FLOAT
+ 10.1010101010, # T_DOUBLE
+ "hi" # T_STRING_INPLACE
+ )
class ReadWriteTests(unittest.TestCase):
@@ -52,6 +65,12 @@ class ReadWriteTests(unittest.TestCase):
ts.T_ULONG = ULONG_MAX
self.assertEqual(ts.T_ULONG, ULONG_MAX)
+ def test_py_ssize_t(self):
+ ts.T_PYSSIZET = PY_SSIZE_T_MAX
+ self.assertEqual(ts.T_PYSSIZET, PY_SSIZE_T_MAX)
+ ts.T_PYSSIZET = PY_SSIZE_T_MIN
+ self.assertEqual(ts.T_PYSSIZET, PY_SSIZE_T_MIN)
+
@unittest.skipUnless(hasattr(ts, "T_LONGLONG"), "long long not present")
def test_longlong(self):
ts.T_LONGLONG = LLONG_MAX
@@ -68,6 +87,24 @@ class ReadWriteTests(unittest.TestCase):
ts.T_ULONGLONG = 4
self.assertEqual(ts.T_ULONGLONG, 4)
+ def test_bad_assignments(self):
+ integer_attributes = [
+ 'T_BOOL',
+ 'T_BYTE', 'T_UBYTE',
+ 'T_SHORT', 'T_USHORT',
+ 'T_INT', 'T_UINT',
+ 'T_LONG', 'T_ULONG',
+ 'T_PYSSIZET'
+ ]
+ if hasattr(ts, 'T_LONGLONG'):
+ integer_attributes.extend(['T_LONGLONG', 'T_ULONGLONG'])
+
+ # issue8014: this produced 'bad argument to internal function'
+ # internal error
+ for nonint in None, 3.2j, "full of eels", {}, []:
+ for attr in integer_attributes:
+ self.assertRaises(TypeError, setattr, ts, attr, nonint)
+
def test_inplace_string(self):
self.assertEqual(ts.T_STRING_INPLACE, "hi")
self.assertRaises(TypeError, setattr, ts, "T_STRING_INPLACE", "s")
@@ -77,32 +114,32 @@ class ReadWriteTests(unittest.TestCase):
class TestWarnings(unittest.TestCase):
def test_byte_max(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_BYTE = CHAR_MAX+1
def test_byte_min(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_BYTE = CHAR_MIN-1
def test_ubyte_max(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_UBYTE = UCHAR_MAX+1
def test_short_max(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_SHORT = SHRT_MAX+1
def test_short_min(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_SHORT = SHRT_MIN-1
def test_ushort_max(self):
- with test_support.check_warnings(('', RuntimeWarning)):
+ with support.check_warnings(('', RuntimeWarning)):
ts.T_USHORT = USHRT_MAX+1
def test_main(verbose=None):
- test_support.run_unittest(__name__)
+ support.run_unittest(__name__)
if __name__ == "__main__":
test_main(verbose=True)