diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-03-29 16:58:21 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-03-29 16:58:21 (GMT) |
commit | b40b947c864e42e81718be1384110a1ac66f1a96 (patch) | |
tree | 378c294db58cf5ad4eb28ebd362428ff8bd1f40d /Lib/test | |
parent | 4feda2abc287fcde4ac57364b0cad3756d534fb3 (diff) | |
download | cpython-b40b947c864e42e81718be1384110a1ac66f1a96.zip cpython-b40b947c864e42e81718be1384110a1ac66f1a96.tar.gz cpython-b40b947c864e42e81718be1384110a1ac66f1a96.tar.bz2 |
Issue #5463: Remove _PY_STRUCT_RANGE_CHECKING constant from struct
module, and remove associated code from test_struct. This was a
mechanism for skipping some of the tests for overflow behaviour when
packing integers; it's no longer necessary.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_struct.py | 74 |
1 files changed, 26 insertions, 48 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 1d10b8f..beeee8f 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -14,10 +14,8 @@ del sys try: import _struct except ImportError: - PY_STRUCT_RANGE_CHECKING = 0 PY_STRUCT_FLOAT_COERCE = 2 else: - PY_STRUCT_RANGE_CHECKING = getattr(_struct, '_PY_STRUCT_RANGE_CHECKING', 0) PY_STRUCT_FLOAT_COERCE = getattr(_struct, '_PY_STRUCT_FLOAT_COERCE', 0) def string_reverse(s): @@ -40,20 +38,6 @@ def with_warning_restore(func): return func(*args, **kw) return decorator -@with_warning_restore -def deprecated_err(func, *args): - try: - func(*args) - except (struct.error, OverflowError): - pass - except DeprecationWarning: - raise TestFailed("%s%s expected to raise DeprecationWarning" % ( - func.__name__, args)) - else: - raise TestFailed("%s%s did not raise error" % ( - func.__name__, args)) - - class StructTest(unittest.TestCase): @with_warning_restore @@ -222,12 +206,6 @@ class StructTest(unittest.TestCase): class IntTester(unittest.TestCase): - # XXX Most std integer modes fail to test for out-of-range. - # The "i" and "l" codes appear to range-check OK on 32-bit boxes, but - # fail to check correctly on some 64-bit ones (Tru64 Unix + Compaq C - # reported by Mark Favas). - BUGGY_RANGE_CHECK = "bBhHiIlL" - def __init__(self, formatpair, bytesize): self.assertEqual(len(formatpair), 2) self.formatpair = formatpair @@ -291,12 +269,10 @@ class StructTest(unittest.TestCase): else: # x is out of range -- verify pack realizes that. - if not PY_STRUCT_RANGE_CHECKING and code in self.BUGGY_RANGE_CHECK: - if verbose: - print("Skipping buggy range check for code", code) - else: - deprecated_err(pack, ">" + code, x) - deprecated_err(pack, "<" + code, x) + self.assertRaises((struct.error, OverflowError), + pack, ">" + code, x) + self.assertRaises((struct.error, OverflowError), + pack, "<" + code, x) # Much the same for unsigned. code = self.unsigned_code @@ -340,12 +316,10 @@ class StructTest(unittest.TestCase): else: # x is out of range -- verify pack realizes that. - if not PY_STRUCT_RANGE_CHECKING and code in self.BUGGY_RANGE_CHECK: - if verbose: - print("Skipping buggy range check for code", code) - else: - deprecated_err(pack, ">" + code, x) - deprecated_err(pack, "<" + code, x) + self.assertRaises((struct.error, OverflowError), + pack, ">" + code, x) + self.assertRaises((struct.error, OverflowError), + pack, "<" + code, x) def run(self): from random import randrange @@ -443,20 +417,24 @@ class StructTest(unittest.TestCase): big = math.ldexp(big, 127 - 24) self.assertRaises(OverflowError, struct.pack, ">f", big) - if PY_STRUCT_RANGE_CHECKING: - def test_1229380(self): - # SF bug 1229380. No struct.pack exception for some out of - # range integers - import sys - for endian in ('', '>', '<'): - for fmt in ('B', 'H', 'I', 'L'): - deprecated_err(struct.pack, endian + fmt, -1) - - deprecated_err(struct.pack, endian + 'B', 300) - deprecated_err(struct.pack, endian + 'H', 70000) - - deprecated_err(struct.pack, endian + 'I', sys.maxsize * 4) - deprecated_err(struct.pack, endian + 'L', sys.maxsize * 4) + def test_1229380(self): + # SF bug 1229380. No struct.pack exception for some out of + # range integers + import sys + for endian in ('', '>', '<'): + for fmt in ('B', 'H', 'I', 'L'): + self.assertRaises((struct.error, OverflowError), struct.pack, + endian + fmt, -1) + + self.assertRaises((struct.error, OverflowError), struct.pack, + endian + 'B', 300) + self.assertRaises((struct.error, OverflowError), struct.pack, + endian + 'H', 70000) + + self.assertRaises((struct.error, OverflowError), struct.pack, + endian + 'I', sys.maxsize * 4) + self.assertRaises((struct.error, OverflowError), struct.pack, + endian + 'L', sys.maxsize * 4) def XXXtest_1530559(self): # XXX This is broken: see the bug report |