summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-02-06 20:44:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-02-06 20:44:27 (GMT)
commita146bef02bf26b75d8d720f444283e28e784a1e3 (patch)
tree4136d8aaae59bddf6030f359ed80f4a9b5221157
parent303718c3d7b650f946a6364f50c9048a1100535b (diff)
downloadcpython-a146bef02bf26b75d8d720f444283e28e784a1e3.zip
cpython-a146bef02bf26b75d8d720f444283e28e784a1e3.tar.gz
cpython-a146bef02bf26b75d8d720f444283e28e784a1e3.tar.bz2
Catch deprecation warnings emitted when non-integers are formatted with %c, %o
and %x (introduced in issue #19995).
-rw-r--r--Lib/test/string_tests.py3
-rw-r--r--Lib/test/test_format.py15
2 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index ef995e2..4345687 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -1179,7 +1179,8 @@ class MixinStrUnicodeUserStringTest:
self.checkraises(TypeError, 'abc', '__mod__')
self.checkraises(TypeError, '%(foo)s', '__mod__', 42)
self.checkraises(TypeError, '%s%s', '__mod__', (42,))
- self.checkraises(TypeError, '%c', '__mod__', (None,))
+ with self.assertWarns(DeprecationWarning):
+ self.checkraises(TypeError, '%c', '__mod__', (None,))
self.checkraises(ValueError, '%(foo', '__mod__', {})
self.checkraises(TypeError, '%(foo)s %(bar)s', '__mod__', ('foo', 42))
self.checkraises(TypeError, '%d', '__mod__', "42") # not numeric
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index 29330f9..015d68e 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -142,7 +142,8 @@ 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)
+ with self.assertWarns(DeprecationWarning):
+ testformat("%x", float(big), "123456_______________", 6)
big = 0o12345670123456701234567012345670 # 32 octal digits
testformat("%o", big, "12345670123456701234567012345670")
testformat("%o", -big, "-12345670123456701234567012345670")
@@ -182,7 +183,8 @@ 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)
+ with self.assertWarns(DeprecationWarning):
+ testformat("%o", float(big), "123456__________________________", 6)
# Some small ints, in both Python int and flavors).
testformat("%d", 42, "42")
testformat("%d", -42, "-42")
@@ -193,7 +195,8 @@ class FormatTest(unittest.TestCase):
testformat("%#x", 1, "0x1")
testformat("%#X", 1, "0X1")
testformat("%#X", 1, "0X1")
- testformat("%#x", 1.0, "0x1")
+ with self.assertWarns(DeprecationWarning):
+ testformat("%#x", 1.0, "0x1")
testformat("%#o", 1, "0o1")
testformat("%#o", 1, "0o1")
testformat("%#o", 0, "0o0")
@@ -210,12 +213,14 @@ class FormatTest(unittest.TestCase):
testformat("%x", -0x42, "-42")
testformat("%x", 0x42, "42")
testformat("%x", -0x42, "-42")
- testformat("%x", float(0x42), "42")
+ with self.assertWarns(DeprecationWarning):
+ 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")
+ with self.assertWarns(DeprecationWarning):
+ testformat("%o", float(0o42), "42")
testformat("%r", "\u0378", "'\\u0378'") # non printable
testformat("%a", "\u0378", "'\\u0378'") # non printable
testformat("%r", "\u0374", "'\u0374'") # printable