From 5075416b8fedc5526b643dabc915f7945fa0d969 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 3 Aug 2017 11:45:23 +0300 Subject: bpo-30978: str.format_map() now passes key lookup exceptions through. (#2790) Previously any exception was replaced with a KeyError exception. --- Lib/test/test_unicode.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Lib/test/test_unicode.py') diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 506f0715c2e..341007b6507 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): -- cgit v1.2.3