diff options
author | Eric Smith <eric@trueblade.com> | 2008-07-15 13:02:41 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2008-07-15 13:02:41 (GMT) |
commit | b1ebcc6b0b2dfee5c7e412b3e1875290213ea4aa (patch) | |
tree | 526c3d2cbcd3aeb8e537bbe941d82fb97cb0b4da /Lib | |
parent | e840b9ad510cf7034f08b1b1527a790be708e414 (diff) | |
download | cpython-b1ebcc6b0b2dfee5c7e412b3e1875290213ea4aa.zip cpython-b1ebcc6b0b2dfee5c7e412b3e1875290213ea4aa.tar.gz cpython-b1ebcc6b0b2dfee5c7e412b3e1875290213ea4aa.tar.bz2 |
Forward port of r64958.
Added '#' formatting to integers. This adds the 0b, 0o, or 0x prefix for bin, oct, hex. There's still one failing case, and I need to finish the docs. I hope to finish those today.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_types.py | 38 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 4 |
2 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index d7deea0..360cfe4 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -293,6 +293,40 @@ class TypesTests(unittest.TestCase): test(1234, "+b", "+10011010010") test(-1234, "+b", "-10011010010") + # alternate (#) formatting + test(0, "#b", '0b0') + test(0, "-#b", '0b0') + test(1, "-#b", '0b1') + test(-1, "-#b", '-0b1') + test(-1, "-#5b", ' -0b1') + test(1, "+#5b", ' +0b1') + test(100, "+#b", '+0b1100100') +# test(100, "#012b", '0b001100100') + + test(0, "#o", '0o0') + test(0, "-#o", '0o0') + test(1, "-#o", '0o1') + test(-1, "-#o", '-0o1') + test(-1, "-#5o", ' -0o1') + test(1, "+#5o", ' +0o1') + test(100, "+#o", '+0o144') + + test(0, "#x", '0x0') + test(0, "-#x", '0x0') + test(1, "-#x", '0x1') + test(-1, "-#x", '-0x1') + test(-1, "-#5x", ' -0x1') + test(1, "+#5x", ' +0x1') + test(100, "+#x", '+0x64') + + test(0, "#X", '0X0') + test(0, "-#X", '0X0') + test(1, "-#X", '0X1') + test(-1, "-#X", '-0X1') + test(-1, "-#5X", ' -0X1') + test(1, "+#5X", ' +0X1') + test(100, "+#X", '+0X64') + # make sure these are errors # precision disallowed @@ -509,6 +543,10 @@ class TypesTests(unittest.TestCase): self.assertRaises(ValueError, format, 1e-100, format_spec) self.assertRaises(ValueError, format, -1e-100, format_spec) + # Alternate formatting is not supported + self.assertRaises(ValueError, format, 0.0, '#') + self.assertRaises(ValueError, format, 0.0, '#20f') + def test_main(): run_unittest(TypesTests) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index fb904bf..e6b3cb0 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -700,6 +700,10 @@ class UnicodeTest( self.assertRaises(ValueError, format, "", "-") self.assertRaises(ValueError, "{0:=s}".format, '') + # Alternate formatting is not supported + self.assertRaises(ValueError, format, '', '#') + self.assertRaises(ValueError, format, '', '#20') + def test_formatting(self): string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) # Testing Unicode formatting strings... |