0001 """Test correct treatment of hex/oct constants. 0002 0003 This is complex because of changes due to PEP 237. 0004 """ 0005 0006 import sys 0007 platform_long_is_32_bits = sys.maxint == 2147483647 0008 0009 import unittest 0010 from test import test_support 0011 0012 import warnings 0013 warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning, 0014 "<string>") 0015 0016 class TextHexOct(unittest.TestCase): 0017 0018 def test_hex_baseline(self): 0019 # Baseline tests 0020 self.assertEqual(0x0, 0) 0021 self.assertEqual(0x10, 16) 0022 if platform_long_is_32_bits: 0023 self.assertEqual(0x7fffffff, 2147483647) 0024 else: 0025 self.assertEqual(0x7fffffffffffffff, 9223372036854775807) 0026 # Ditto with a minus sign and parentheses 0027 self.assertEqual(-(0x0), 0) 0028 self.assertEqual(-(0x10), -16) 0029 if platform_long_is_32_bits: 0030 self.assertEqual(-(0x7fffffff), -2147483647) 0031 else: 0032 self.assertEqual(-(0x7fffffffffffffff), -9223372036854775807) 0033 # Ditto with a minus sign and NO parentheses 0034 self.assertEqual(-0x0, 0) 0035 self.assertEqual(-0x10, -16) 0036 if platform_long_is_32_bits: 0037 self.assertEqual(-0x7fffffff, -2147483647) 0038 else: 0039 self.assertEqual(-0x7fffffffffffffff, -9223372036854775807) 0040 0041 def test_hex_unsigned(self): 0042 if platform_long_is_32_bits: 0043 # Positive constants 0044 self.assertEqual(0x80000000, 2147483648L) 0045 self.assertEqual(0xffffffff, 4294967295L) 0046 # Ditto with a minus sign and parentheses 0047 self.assertEqual(-(0x80000000), -2147483648L) 0048 self.assertEqual(-(0xffffffff), -4294967295L) 0049 # Ditto with a minus sign and NO parentheses 0050 # This failed in Python 2.2 through 2.2.2 and in 2.3a1 0051 self.assertEqual(-0x80000000, -2147483648L) 0052 self.assertEqual(-0xffffffff, -4294967295L) 0053 else: 0054 # Positive constants 0055 self.assertEqual(0x8000000000000000, 9223372036854775808L) 0056 self.assertEqual(0xffffffffffffffff, 18446744073709551615L) 0057 # Ditto with a minus sign and parentheses 0058 self.assertEqual(-(0x8000000000000000), -9223372036854775808L) 0059 self.assertEqual(-(0xffffffffffffffff), -18446744073709551615L) 0060 # Ditto with a minus sign and NO parentheses 0061 # This failed in Python 2.2 through 2.2.2 and in 2.3a1 0062 self.assertEqual(-0x8000000000000000, -9223372036854775808L) 0063 self.assertEqual(-0xffffffffffffffff, -18446744073709551615L) 0064 0065 def test_oct_baseline(self): 0066 # Baseline tests 0067 self.assertEqual(00, 0) 0068 self.assertEqual(020, 16) 0069 if platform_long_is_32_bits: 0070 self.assertEqual(017777777777, 2147483647) 0071 else: 0072 self.assertEqual(0777777777777777777777, 9223372036854775807) 0073 # Ditto with a minus sign and parentheses 0074 self.assertEqual(-(00), 0) 0075 self.assertEqual(-(020), -16) 0076 if platform_long_is_32_bits: 0077 self.assertEqual(-(017777777777), -2147483647) 0078 else: 0079 self.assertEqual(-(0777777777777777777777), -9223372036854775807) 0080 # Ditto with a minus sign and NO parentheses 0081 self.assertEqual(-00, 0) 0082 self.assertEqual(-020, -16) 0083 if platform_long_is_32_bits: 0084 self.assertEqual(-017777777777, -2147483647) 0085 else: 0086 self.assertEqual(-0777777777777777777777, -9223372036854775807) 0087 0088 def test_oct_unsigned(self): 0089 if platform_long_is_32_bits: 0090 # Positive constants 0091 self.assertEqual(020000000000, 2147483648L) 0092 self.assertEqual(037777777777, 4294967295L) 0093 # Ditto with a minus sign and parentheses 0094 self.assertEqual(-(020000000000), -2147483648L) 0095 self.assertEqual(-(037777777777), -4294967295L) 0096 # Ditto with a minus sign and NO parentheses 0097 # This failed in Python 2.2 through 2.2.2 and in 2.3a1 0098 self.assertEqual(-020000000000, -2147483648L) 0099 self.assertEqual(-037777777777, -4294967295L) 0100 else: 0101 # Positive constants 0102 self.assertEqual(01000000000000000000000, 9223372036854775808L) 0103 self.assertEqual(01777777777777777777777, 18446744073709551615L) 0104 # Ditto with a minus sign and parentheses 0105 self.assertEqual(-(01000000000000000000000), -9223372036854775808L) 0106 self.assertEqual(-(01777777777777777777777), -18446744073709551615L) 0107 # Ditto with a minus sign and NO parentheses 0108 # This failed in Python 2.2 through 2.2.2 and in 2.3a1 0109 self.assertEqual(-01000000000000000000000, -9223372036854775808L) 0110 self.assertEqual(-01777777777777777777777, -18446744073709551615L) 0111 0112 def test_main(): 0113 test_support.run_unittest(TextHexOct) 0114 0115 if __name__ == "__main__": 0116 test_main() 0117
Generated by PyXR 0.9.4