From 72363031b9d2b382d6d8c8703f716da982dcbbdf Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 6 Mar 2007 13:35:00 +0000 Subject: [PATCH] A test case for the defaultdict KeyError bug. --- Lib/test/test_defaultdict.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py index 1834f9071ae..08be005b424 100644 --- a/Lib/test/test_defaultdict.py +++ b/Lib/test/test_defaultdict.py @@ -132,6 +132,15 @@ class TestDefaultDict(unittest.TestCase): self.assertEqual(d2.default_factory, list) self.assertEqual(d2, d1) + def test_keyerror_without_factory(self): + d1 = defaultdict() + try: + d1[(1,)] + except KeyError, err: + self.assertEqual(err.message, (1,)) + else: + self.fail("expected KeyError") + def test_main(): test_support.run_unittest(TestDefaultDict)