diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_b1.py | 14 | ||||
-rw-r--r-- | Lib/test/test_long.py | 24 | ||||
-rw-r--r-- | Lib/test/test_types.py | 12 |
3 files changed, 28 insertions, 22 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index 249f1fa..3033667 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -438,17 +438,19 @@ try: except: raise TestFailed, "int(%s)" % `s[1:]` + " should return long" try: - int(1e100) + x = int(1e100) except OverflowError: - pass + raise TestFailed("int(1e100) mustn't raise OverflowError") else: - raise TestFailed("int(1e100) expected OverflowError") + if not isinstance(x, long): + raise TestFailed("int(1e100) should have returned long") try: - int(-1e100) + x = int(-1e100) except OverflowError: - pass + raise TestFailed("int(-1e100) mustn't raise OverflowError") else: - raise TestFailed("int(-1e100) expected OverflowError") + if not isinstance(x, long): + raise TestFailed("int(-1e100) should have returned long") # SF bug 434186: 0x80000000/2 != 0x80000000>>1. diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 9319734..9cab2de 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -267,22 +267,26 @@ def test_misc(maxdigits=MAXDIGITS): # but long -> int should overflow for hugepos+1 and hugeneg-1 x = hugepos_aslong + 1 try: - int(x) - raise ValueError + y = int(x) except OverflowError: - pass - except: - raise TestFailed, "int(long(sys.maxint) + 1) didn't overflow" + raise TestFailed, "int(long(sys.maxint) + 1) mustn't overflow" + if not isinstance(y, long): + raise TestFailed("int(long(sys.maxint) + 1) should have returned long") x = hugeneg_aslong - 1 try: - int(x) - raise ValueError + y = int(x) except OverflowError: - pass - except: - raise TestFailed, "int(long(-sys.maxint-1) - 1) didn't overflow" + raise TestFailed, "int(long(-sys.maxint-1) - 1) mustn't overflow" + if not isinstance(y, long): + raise TestFailed("int(long(-sys.maxint-1) - 1) should have returned long") + class long2(long): + pass + x = long2(1L<<100) + y = int(x) + if type(y) is not long: + raise TestFailed("overflowing int conversion must return long not long subtype") # ----------------------------------- tests of auto int->long conversion def test_auto_overflow(): diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index d075d94..c20af2e 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -138,16 +138,16 @@ if not 12L < 24L: raise TestFailed, 'long op' if not -24L < -12L: raise TestFailed, 'long op' x = sys.maxint if int(long(x)) != x: raise TestFailed, 'long op' -try: int(long(x)+1L) -except OverflowError: pass -else:raise TestFailed, 'long op' +try: y = int(long(x)+1L) +except OverflowError: raise TestFailed, 'long op' +if not isinstance(y, long): raise TestFailed, 'long op' x = -x if int(long(x)) != x: raise TestFailed, 'long op' x = x-1 if int(long(x)) != x: raise TestFailed, 'long op' -try: int(long(x)-1L) -except OverflowError: pass -else:raise TestFailed, 'long op' +try: y = int(long(x)-1L) +except OverflowError: raise TestFailed, 'long op' +if not isinstance(y, long): raise TestFailed, 'long op' try: 5 << -5 except ValueError: pass |