summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unicode.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-08-03 08:45:23 (GMT)
committerGitHub <noreply@github.com>2017-08-03 08:45:23 (GMT)
commit5075416b8fedc5526b643dabc915f7945fa0d969 (patch)
tree31e23d9e4dbda6c41dc8faf831cc543e9e4e89c9 /Lib/test/test_unicode.py
parent25e4f779d7ae9f37a1933cb5cbfad06e673c01f9 (diff)
downloadcpython-5075416b8fedc5526b643dabc915f7945fa0d969.zip
cpython-5075416b8fedc5526b643dabc915f7945fa0d969.tar.gz
cpython-5075416b8fedc5526b643dabc915f7945fa0d969.tar.bz2
bpo-30978: str.format_map() now passes key lookup exceptions through. (#2790)
Previously any exception was replaced with a KeyError exception.
Diffstat (limited to 'Lib/test/test_unicode.py')
-rw-r--r--Lib/test/test_unicode.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 506f071..341007b 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1278,6 +1278,13 @@ class UnicodeTest(string_tests.CommonTest,
self.assertRaises(ValueError, '{}'.format_map, 'a')
self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1})
+ class BadMapping:
+ def __getitem__(self, key):
+ return 1/0
+ self.assertRaises(KeyError, '{a}'.format_map, {})
+ self.assertRaises(TypeError, '{a}'.format_map, [])
+ self.assertRaises(ZeroDivisionError, '{a}'.format_map, BadMapping())
+
def test_format_huge_precision(self):
format_string = ".{}f".format(sys.maxsize + 1)
with self.assertRaises(ValueError):