diff options
author | Guido van Rossum <guido@python.org> | 2003-11-29 23:52:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-11-29 23:52:13 (GMT) |
commit | 6c9e130524533263b690e86639a36b6f3e7a8eeb (patch) | |
tree | 39023f825688f630245ddcaa60af9942a859522c /Lib | |
parent | 37e136373e0d9ab3bdf25ecd9c42b86281ed21d3 (diff) | |
download | cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.zip cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.tar.gz cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.tar.bz2 |
- Removed FutureWarnings related to hex/oct literals and conversions
and left shifts. (Thanks to Kalle Svensson for SF patch 849227.)
This addresses most of the remaining semantic changes promised by
PEP 237, except for repr() of a long, which still shows the trailing
'L'. The PEP appears to promise warnings for operations that
changed semantics compared to Python 2.3, but this is not
implemented; we've suffered through enough warnings related to
hex/oct literals and I think it's best to be silent now.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_builtin.py | 5 | ||||
-rw-r--r-- | Lib/test/test_compile.py | 19 | ||||
-rw-r--r-- | Lib/test/test_format.py | 7 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 12 | ||||
-rw-r--r-- | Lib/test/test_hexoct.py | 64 |
5 files changed, 49 insertions, 58 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index d47a9da..1953f29 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -437,8 +437,7 @@ class BuiltinTest(unittest.TestCase): def test_hex(self): self.assertEqual(hex(16), '0x10') self.assertEqual(hex(16L), '0x10L') - self.assertEqual(len(hex(-1)), len(hex(sys.maxint))) - self.assert_(hex(-16) in ('0xfffffff0', '0xfffffffffffffff0')) + self.assertEqual(hex(-16), '-0x10') self.assertEqual(hex(-16L), '-0x10L') self.assertRaises(TypeError, hex, {}) @@ -757,7 +756,7 @@ class BuiltinTest(unittest.TestCase): def test_oct(self): self.assertEqual(oct(100), '0144') self.assertEqual(oct(100L), '0144L') - self.assert_(oct(-100) in ('037777777634', '01777777777777777777634')) + self.assertEqual(oct(-100), '-0144') self.assertEqual(oct(-100L), '-0144L') self.assertRaises(TypeError, oct, ()) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 4d4ba4f..e2b1c95 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -119,15 +119,18 @@ if 1: def test_unary_minus(self): # Verify treatment of unary minus on negative numbers SF bug #660455 - warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning) - warnings.filterwarnings("ignore", "hex.* of negative int", FutureWarning) - # XXX Of course the following test will have to be changed in Python 2.4 - # This test is in a <string> so the filterwarnings() can affect it - all_one_bits = '0xffffffff' - if sys.maxint != 2147483647: + if sys.maxint == 2147483647: + # 32-bit machine + all_one_bits = '0xffffffff' + self.assertEqual(eval(all_one_bits), 4294967295L) + self.assertEqual(eval("-" + all_one_bits), -4294967295L) + elif sys.maxint == 9223372036854775807: + # 64-bit machine all_one_bits = '0xffffffffffffffff' - self.assertEqual(eval(all_one_bits), -1) - self.assertEqual(eval("-" + all_one_bits), 1) + self.assertEqual(eval(all_one_bits), 18446744073709551615L) + self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L) + else: + self.fail("How many bits *does* this machine have???") def test_sequence_unpacking_error(self): # Verify sequence packing/unpacking with "or". SF bug #757818 diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py index f791874..0a51231 100644 --- a/Lib/test/test_format.py +++ b/Lib/test/test_format.py @@ -183,12 +183,12 @@ testboth("%#X", 0, "0X0") testboth("%#X", 0L, "0X0") testboth("%x", 0x42, "42") -# testboth("%x", -0x42, "ffffffbe") # specific to 32-bit boxes; see below +testboth("%x", -0x42, "-42") testboth("%x", 0x42L, "42") testboth("%x", -0x42L, "-42") testboth("%o", 042, "42") -# testboth("%o", -042, "37777777736") # specific to 32-bit boxes; see below +testboth("%o", -042, "-42") testboth("%o", 042L, "42") testboth("%o", -042L, "-42") @@ -238,6 +238,3 @@ if sys.maxint == 2**32-1: pass else: raise TestFailed, '"%*d"%(sys.maxint, -127) should fail' - # (different things go wrong on a 64 bit box...) - testboth("%x", -0x42, "ffffffbe") - testboth("%o", -042, "37777777736") diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index c57bbed..6666c13 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -39,20 +39,20 @@ except ImportError: if maxint == 2147483647: # The following test will start to fail in Python 2.4; # change the 020000000000 to -020000000000 - if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int' + if -2147483647-1 != -020000000000: raise TestFailed, 'max negative int' # XXX -2147483648 - if 037777777777 != -1: raise TestFailed, 'oct -1' - if 0xffffffff != -1: raise TestFailed, 'hex -1' + if 037777777777 < 0: raise TestFailed, 'large oct' + if 0xffffffff < 0: raise TestFailed, 'large hex' for s in '2147483648', '040000000000', '0x100000000': try: x = eval(s) except OverflowError: print "OverflowError on huge integer literal " + `s` elif eval('maxint == 9223372036854775807'): - if eval('-9223372036854775807-1 != 01000000000000000000000'): + if eval('-9223372036854775807-1 != -01000000000000000000000'): raise TestFailed, 'max negative int' - if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1' - if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1' + if eval('01777777777777777777777') < 0: raise TestFailed, 'large oct' + if eval('0xffffffffffffffff') < 0: raise TestFailed, 'large hex' for s in '9223372036854775808', '02000000000000000000000', \ '0x10000000000000000': try: diff --git a/Lib/test/test_hexoct.py b/Lib/test/test_hexoct.py index 8a57906..f71dbe0 100644 --- a/Lib/test/test_hexoct.py +++ b/Lib/test/test_hexoct.py @@ -1,8 +1,6 @@ """Test correct treatment of hex/oct constants. This is complex because of changes due to PEP 237. - -Some of these tests will have to change in Python 2.4! """ import sys @@ -41,31 +39,28 @@ class TextHexOct(unittest.TestCase): self.assertEqual(-0x7fffffffffffffff, -9223372036854775807) def test_hex_unsigned(self): - # This test is in a <string> so we can ignore the warnings - exec """if 1: if platform_long_is_32_bits: - # Positive-looking constants with negavive values - self.assertEqual(0x80000000, -2147483648L) - self.assertEqual(0xffffffff, -1) + # Positive constants + self.assertEqual(0x80000000, 2147483648L) + self.assertEqual(0xffffffff, 4294967295L) # Ditto with a minus sign and parentheses - self.assertEqual(-(0x80000000), 2147483648L) - self.assertEqual(-(0xffffffff), 1) + self.assertEqual(-(0x80000000), -2147483648L) + self.assertEqual(-(0xffffffff), -4294967295L) # Ditto with a minus sign and NO parentheses # This failed in Python 2.2 through 2.2.2 and in 2.3a1 - self.assertEqual(-0x80000000, 2147483648L) - self.assertEqual(-0xffffffff, 1) + self.assertEqual(-0x80000000, -2147483648L) + self.assertEqual(-0xffffffff, -4294967295L) else: - # Positive-looking constants with negavive values - self.assertEqual(0x8000000000000000, -9223372036854775808L) - self.assertEqual(0xffffffffffffffff, -1) + # Positive constants + self.assertEqual(0x8000000000000000, 9223372036854775808L) + self.assertEqual(0xffffffffffffffff, 18446744073709551615L) # Ditto with a minus sign and parentheses - self.assertEqual(-(0x8000000000000000), 9223372036854775808L) - self.assertEqual(-(0xffffffffffffffff), 1) + self.assertEqual(-(0x8000000000000000), -9223372036854775808L) + self.assertEqual(-(0xffffffffffffffff), -18446744073709551615L) # Ditto with a minus sign and NO parentheses # This failed in Python 2.2 through 2.2.2 and in 2.3a1 - self.assertEqual(-0x8000000000000000, 9223372036854775808L) - self.assertEqual(-0xffffffffffffffff, 1) - \n""" + self.assertEqual(-0x8000000000000000, -9223372036854775808L) + self.assertEqual(-0xffffffffffffffff, -18446744073709551615L) def test_oct_baseline(self): # Baseline tests @@ -91,31 +86,28 @@ class TextHexOct(unittest.TestCase): self.assertEqual(-0777777777777777777777, -9223372036854775807) def test_oct_unsigned(self): - # This test is in a <string> so we can ignore the warnings - exec """if 1: if platform_long_is_32_bits: - # Positive-looking constants with negavive values - self.assertEqual(020000000000, -2147483648L) - self.assertEqual(037777777777, -1) + # Positive constants + self.assertEqual(020000000000, 2147483648L) + self.assertEqual(037777777777, 4294967295L) # Ditto with a minus sign and parentheses - self.assertEqual(-(020000000000), 2147483648L) - self.assertEqual(-(037777777777), 1) + self.assertEqual(-(020000000000), -2147483648L) + self.assertEqual(-(037777777777), -4294967295L) # Ditto with a minus sign and NO parentheses # This failed in Python 2.2 through 2.2.2 and in 2.3a1 - self.assertEqual(-020000000000, 2147483648L) - self.assertEqual(-037777777777, 1) + self.assertEqual(-020000000000, -2147483648L) + self.assertEqual(-037777777777, -4294967295L) else: - # Positive-looking constants with negavive values - self.assertEqual(01000000000000000000000, -9223372036854775808L) - self.assertEqual(01777777777777777777777, -1) + # Positive constants + self.assertEqual(01000000000000000000000, 9223372036854775808L) + self.assertEqual(01777777777777777777777, 18446744073709551615L) # Ditto with a minus sign and parentheses - self.assertEqual(-(01000000000000000000000), 9223372036854775808L) - self.assertEqual(-(01777777777777777777777), 1) + self.assertEqual(-(01000000000000000000000), -9223372036854775808L) + self.assertEqual(-(01777777777777777777777), -18446744073709551615L) # Ditto with a minus sign and NO parentheses # This failed in Python 2.2 through 2.2.2 and in 2.3a1 - self.assertEqual(-01000000000000000000000, 9223372036854775808L) - self.assertEqual(-01777777777777777777777, 1) - \n""" + self.assertEqual(-01000000000000000000000, -9223372036854775808L) + self.assertEqual(-01777777777777777777777, -18446744073709551615L) def test_main(): test_support.run_unittest(TextHexOct) |