/Lib/test/test_structmembers.py

http://unladen-swallow.googlecode.com/ · Python · 107 lines · 83 code · 22 blank · 2 comment · 8 complexity · 0e8d7a90c5e3a3363c2aa4a9aff6fcdb MD5 · raw file

  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
  7. import warnings, exceptions, unittest, sys
  8. from test import test_support
  9. ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8,
  10. 9.99999, 10.1010101010)
  11. class ReadWriteTests(unittest.TestCase):
  12. def test_types(self):
  13. ts.T_BOOL = True
  14. self.assertEquals(ts.T_BOOL, True)
  15. ts.T_BOOL = False
  16. self.assertEquals(ts.T_BOOL, False)
  17. self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1)
  18. ts.T_BYTE = CHAR_MAX
  19. self.assertEquals(ts.T_BYTE, CHAR_MAX)
  20. ts.T_BYTE = CHAR_MIN
  21. self.assertEquals(ts.T_BYTE, CHAR_MIN)
  22. ts.T_UBYTE = UCHAR_MAX
  23. self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
  24. ts.T_SHORT = SHRT_MAX
  25. self.assertEquals(ts.T_SHORT, SHRT_MAX)
  26. ts.T_SHORT = SHRT_MIN
  27. self.assertEquals(ts.T_SHORT, SHRT_MIN)
  28. ts.T_USHORT = USHRT_MAX
  29. self.assertEquals(ts.T_USHORT, USHRT_MAX)
  30. ts.T_INT = INT_MAX
  31. self.assertEquals(ts.T_INT, INT_MAX)
  32. ts.T_INT = INT_MIN
  33. self.assertEquals(ts.T_INT, INT_MIN)
  34. ts.T_UINT = UINT_MAX
  35. self.assertEquals(ts.T_UINT, UINT_MAX)
  36. ts.T_LONG = LONG_MAX
  37. self.assertEquals(ts.T_LONG, LONG_MAX)
  38. ts.T_LONG = LONG_MIN
  39. self.assertEquals(ts.T_LONG, LONG_MIN)
  40. ts.T_ULONG = ULONG_MAX
  41. self.assertEquals(ts.T_ULONG, ULONG_MAX)
  42. ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
  43. if hasattr(ts, 'T_LONGLONG'):
  44. ts.T_LONGLONG = LLONG_MAX
  45. self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
  46. ts.T_LONGLONG = LLONG_MIN
  47. self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
  48. ts.T_ULONGLONG = ULLONG_MAX
  49. self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
  50. ## make sure these will accept a plain int as well as a long
  51. ts.T_LONGLONG = 3
  52. self.assertEquals(ts.T_LONGLONG, 3)
  53. ts.T_ULONGLONG = 4
  54. self.assertEquals(ts.T_ULONGLONG, 4)
  55. class TestWarnings(unittest.TestCase):
  56. def has_warned(self, w):
  57. self.assertEqual(w.category, RuntimeWarning)
  58. def test_byte_max(self):
  59. with test_support.check_warnings() as w:
  60. ts.T_BYTE = CHAR_MAX+1
  61. self.has_warned(w)
  62. def test_byte_min(self):
  63. with test_support.check_warnings() as w:
  64. ts.T_BYTE = CHAR_MIN-1
  65. self.has_warned(w)
  66. def test_ubyte_max(self):
  67. with test_support.check_warnings() as w:
  68. ts.T_UBYTE = UCHAR_MAX+1
  69. self.has_warned(w)
  70. def test_short_max(self):
  71. with test_support.check_warnings() as w:
  72. ts.T_SHORT = SHRT_MAX+1
  73. self.has_warned(w)
  74. def test_short_min(self):
  75. with test_support.check_warnings() as w:
  76. ts.T_SHORT = SHRT_MIN-1
  77. self.has_warned(w)
  78. def test_ushort_max(self):
  79. with test_support.check_warnings() as w:
  80. ts.T_USHORT = USHRT_MAX+1
  81. self.has_warned(w)
  82. def test_main(verbose=None):
  83. test_support.run_unittest(__name__)
  84. if __name__ == "__main__":
  85. test_main(verbose=True)