summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-08-03 09:14:07 (GMT)
committerGitHub <noreply@github.com>2017-08-03 09:14:07 (GMT)
commitf08b2be4416163e3d18b8d09891e7cda0d8a21d4 (patch)
tree90c0ef4c2509e79c801805d1901169e63e901466 /Lib/test
parentf142e85d22ba135d5205280240f3a2fe1df2649f (diff)
downloadcpython-f08b2be4416163e3d18b8d09891e7cda0d8a21d4.zip
cpython-f08b2be4416163e3d18b8d09891e7cda0d8a21d4.tar.gz
cpython-f08b2be4416163e3d18b8d09891e7cda0d8a21d4.tar.bz2
[3.6] bpo-30978: str.format_map() now passes key lookup exceptions through. (GH-2790) (#2992)
Previously any exception was replaced with a KeyError exception. (cherry picked from commit 5075416)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_re.py2
-rw-r--r--Lib/test/test_unicode.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index a6cbbd0..e23e5a9 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -471,7 +471,7 @@ class ReTests(unittest.TestCase):
m[(0,)]
with self.assertRaisesRegex(IndexError, 'no such group'):
m[(0, 1)]
- with self.assertRaisesRegex(KeyError, 'a2'):
+ with self.assertRaisesRegex(IndexError, 'no such group'):
'a1={a2}'.format_map(m)
m = pat.match('ac')
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 2844bc5..56ab0ad 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1279,6 +1279,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):