Changeset 391 for python/trunk/Lib/test/test_structmembers.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_structmembers.py
r2 r391 1 from _testcapi import test_structmembersType, \1 from _testcapi import _test_structmembersType, \ 2 2 CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ 3 3 SHRT_MAX, SHRT_MIN, USHRT_MAX, \ … … 6 6 LLONG_MAX, LLONG_MIN, ULLONG_MAX 7 7 8 import warnings, exceptions, unittest, sys8 import unittest 9 9 from test import test_support 10 10 11 ts= test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,12 9.99999, 10.1010101010 )11 ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8, 12 9.99999, 10.1010101010, "hi") 13 13 14 14 class ReadWriteTests(unittest.TestCase): 15 def test_types(self): 15 16 def test_bool(self): 16 17 ts.T_BOOL = True 17 self.assertEqual s(ts.T_BOOL, True)18 self.assertEqual(ts.T_BOOL, True) 18 19 ts.T_BOOL = False 19 self.assertEqual s(ts.T_BOOL, False)20 self.assertEqual(ts.T_BOOL, False) 20 21 self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1) 21 22 23 def test_byte(self): 22 24 ts.T_BYTE = CHAR_MAX 23 self.assertEqual s(ts.T_BYTE, CHAR_MAX)25 self.assertEqual(ts.T_BYTE, CHAR_MAX) 24 26 ts.T_BYTE = CHAR_MIN 25 self.assertEqual s(ts.T_BYTE, CHAR_MIN)27 self.assertEqual(ts.T_BYTE, CHAR_MIN) 26 28 ts.T_UBYTE = UCHAR_MAX 27 self.assertEqual s(ts.T_UBYTE, UCHAR_MAX)29 self.assertEqual(ts.T_UBYTE, UCHAR_MAX) 28 30 31 def test_short(self): 29 32 ts.T_SHORT = SHRT_MAX 30 self.assertEqual s(ts.T_SHORT, SHRT_MAX)33 self.assertEqual(ts.T_SHORT, SHRT_MAX) 31 34 ts.T_SHORT = SHRT_MIN 32 self.assertEqual s(ts.T_SHORT, SHRT_MIN)35 self.assertEqual(ts.T_SHORT, SHRT_MIN) 33 36 ts.T_USHORT = USHRT_MAX 34 self.assertEqual s(ts.T_USHORT, USHRT_MAX)37 self.assertEqual(ts.T_USHORT, USHRT_MAX) 35 38 39 def test_int(self): 36 40 ts.T_INT = INT_MAX 37 self.assertEqual s(ts.T_INT, INT_MAX)41 self.assertEqual(ts.T_INT, INT_MAX) 38 42 ts.T_INT = INT_MIN 39 self.assertEqual s(ts.T_INT, INT_MIN)43 self.assertEqual(ts.T_INT, INT_MIN) 40 44 ts.T_UINT = UINT_MAX 41 self.assertEqual s(ts.T_UINT, UINT_MAX)45 self.assertEqual(ts.T_UINT, UINT_MAX) 42 46 47 def test_long(self): 43 48 ts.T_LONG = LONG_MAX 44 self.assertEqual s(ts.T_LONG, LONG_MAX)49 self.assertEqual(ts.T_LONG, LONG_MAX) 45 50 ts.T_LONG = LONG_MIN 46 self.assertEqual s(ts.T_LONG, LONG_MIN)51 self.assertEqual(ts.T_LONG, LONG_MIN) 47 52 ts.T_ULONG = ULONG_MAX 48 self.assertEqual s(ts.T_ULONG, ULONG_MAX)53 self.assertEqual(ts.T_ULONG, ULONG_MAX) 49 54 50 ## T_LONGLONG and T_ULONGLONG may not be present on some platforms51 if hasattr(ts, 'T_LONGLONG'):52 53 self.assertEquals(ts.T_LONGLONG, LLONG_MAX)54 55 self.assertEquals(ts.T_LONGLONG, LLONG_MIN)55 @unittest.skipUnless(hasattr(ts, "T_LONGLONG"), "long long not present") 56 def test_longlong(self): 57 ts.T_LONGLONG = LLONG_MAX 58 self.assertEqual(ts.T_LONGLONG, LLONG_MAX) 59 ts.T_LONGLONG = LLONG_MIN 60 self.assertEqual(ts.T_LONGLONG, LLONG_MIN) 56 61 57 58 self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)62 ts.T_ULONGLONG = ULLONG_MAX 63 self.assertEqual(ts.T_ULONGLONG, ULLONG_MAX) 59 64 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) 65 ## make sure these will accept a plain int as well as a long 66 ts.T_LONGLONG = 3 67 self.assertEqual(ts.T_LONGLONG, 3) 68 ts.T_ULONGLONG = 4 69 self.assertEqual(ts.T_ULONGLONG, 4) 70 71 def test_inplace_string(self): 72 self.assertEqual(ts.T_STRING_INPLACE, "hi") 73 self.assertRaises(TypeError, setattr, ts, "T_STRING_INPLACE", "s") 74 self.assertRaises(TypeError, delattr, ts, "T_STRING_INPLACE") 65 75 66 76 67 77 class TestWarnings(unittest.TestCase): 68 def has_warned(self, w):69 self.assertEqual(w.category, RuntimeWarning)70 78 71 79 def test_byte_max(self): 72 with test_support.check_warnings( ) as w:80 with test_support.check_warnings(('', RuntimeWarning)): 73 81 ts.T_BYTE = CHAR_MAX+1 74 self.has_warned(w)75 82 76 83 def test_byte_min(self): 77 with test_support.check_warnings( ) as w:84 with test_support.check_warnings(('', RuntimeWarning)): 78 85 ts.T_BYTE = CHAR_MIN-1 79 self.has_warned(w)80 86 81 87 def test_ubyte_max(self): 82 with test_support.check_warnings( ) as w:88 with test_support.check_warnings(('', RuntimeWarning)): 83 89 ts.T_UBYTE = UCHAR_MAX+1 84 self.has_warned(w)85 90 86 91 def test_short_max(self): 87 with test_support.check_warnings( ) as w:92 with test_support.check_warnings(('', RuntimeWarning)): 88 93 ts.T_SHORT = SHRT_MAX+1 89 self.has_warned(w)90 94 91 95 def test_short_min(self): 92 with test_support.check_warnings( ) as w:96 with test_support.check_warnings(('', RuntimeWarning)): 93 97 ts.T_SHORT = SHRT_MIN-1 94 self.has_warned(w)95 98 96 99 def test_ushort_max(self): 97 with test_support.check_warnings( ) as w:100 with test_support.check_warnings(('', RuntimeWarning)): 98 101 ts.T_USHORT = USHRT_MAX+1 99 self.has_warned(w)100 101 102 102 103
Note:
See TracChangeset
for help on using the changeset viewer.