summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2014-01-12 07:20:58 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2014-01-12 07:20:58 (GMT)
commitf9bba9c67f7928be185bd81614881ae88a46aaab (patch)
tree6115322a5032536b3dbe72e2ca3a34d92c4878ed /Lib/test
parent57bc1e21e7df2fe85ec87fcc11451939a309a4af (diff)
downloadcpython-f9bba9c67f7928be185bd81614881ae88a46aaab.zip
cpython-f9bba9c67f7928be185bd81614881ae88a46aaab.tar.gz
cpython-f9bba9c67f7928be185bd81614881ae88a46aaab.tar.bz2
Issue19995: issue deprecation warning for non-integer values to %c, %o, %x, %X
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_format.py5
-rw-r--r--Lib/test/test_unicode.py20
2 files changed, 20 insertions, 5 deletions
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index 4b1fdf9..29330f9 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -142,6 +142,7 @@ class FormatTest(unittest.TestCase):
testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
# same, except no 0 flag
testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+ testformat("%x", float(big), "123456_______________", 6)
big = 0o12345670123456701234567012345670 # 32 octal digits
testformat("%o", big, "12345670123456701234567012345670")
testformat("%o", -big, "-12345670123456701234567012345670")
@@ -181,6 +182,7 @@ class FormatTest(unittest.TestCase):
testformat("%034.33o", big, "0012345670123456701234567012345670")
# base marker shouldn't change that
testformat("%0#34.33o", big, "0o012345670123456701234567012345670")
+ testformat("%o", float(big), "123456__________________________", 6)
# Some small ints, in both Python int and flavors).
testformat("%d", 42, "42")
testformat("%d", -42, "-42")
@@ -191,6 +193,7 @@ class FormatTest(unittest.TestCase):
testformat("%#x", 1, "0x1")
testformat("%#X", 1, "0X1")
testformat("%#X", 1, "0X1")
+ testformat("%#x", 1.0, "0x1")
testformat("%#o", 1, "0o1")
testformat("%#o", 1, "0o1")
testformat("%#o", 0, "0o0")
@@ -207,10 +210,12 @@ class FormatTest(unittest.TestCase):
testformat("%x", -0x42, "-42")
testformat("%x", 0x42, "42")
testformat("%x", -0x42, "-42")
+ testformat("%x", float(0x42), "42")
testformat("%o", 0o42, "42")
testformat("%o", -0o42, "-42")
testformat("%o", 0o42, "42")
testformat("%o", -0o42, "-42")
+ testformat("%o", float(0o42), "42")
testformat("%r", "\u0378", "'\\u0378'") # non printable
testformat("%a", "\u0378", "'\\u0378'") # non printable
testformat("%r", "\u0374", "'\u0374'") # printable
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 63883a5..d31838c 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1139,6 +1139,13 @@ class UnicodeTest(string_tests.CommonTest,
self.value = float(value)
def __int__(self):
return int(self.value)
+ def check_depr(modifier, value):
+ with support.check_warnings(
+ ("", DeprecationWarning),
+ quiet=False,
+ ):
+ warnings.simplefilter('always')
+ modifier % value
pi = PsuedoFloat(3.1415)
letter_m = PsuedoInt(109)
self.assertEqual('%x' % 42, '2a')
@@ -1149,11 +1156,14 @@ class UnicodeTest(string_tests.CommonTest,
self.assertEqual('%X' % letter_m, '6D')
self.assertEqual('%o' % letter_m, '155')
self.assertEqual('%c' % letter_m, 'm')
- self.assertRaises(TypeError, '%x'.__mod__, pi)
- self.assertRaises(TypeError, '%x'.__mod__, 3.14)
- self.assertRaises(TypeError, '%X'.__mod__, 2.11)
- self.assertRaises(TypeError, '%o'.__mod__, 1.79)
- self.assertRaises(TypeError, '%c'.__mod__, pi)
+ for mod, value in (
+ ('%x', pi),
+ ('%x', 3.14),
+ ('%X', 2.11),
+ ('%o', 1.79),
+ ('%c', pi),
+ ):
+ check_depr(mod, value)
def test_formatting_with_enum(self):
# issue18780