summaryrefslogtreecommitdiff
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-03-09 22:58:51 +0100
committerVictor Stinner <victor.stinner@gmail.com>2012-03-09 22:58:51 +0100
commit28393828e21fb47672a060cdb4e704be8bc21505 (patch)
tree3f5cd57d5aa6818db83fc31c708d70859a0ef569 /Lib/test/test_dict.py
parent3774977de2995f19c5ef34fadb0b9b4fc2326e6e (diff)
downloadcpython-git-28393828e21fb47672a060cdb4e704be8bc21505.tar.gz
Issue #14205: Fix test_dict.test_mutating_lookup()
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 15db51d3ea..387dd32311 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -392,20 +392,27 @@ class DictTest(unittest.TestCase):
class NastyKey:
mutate_dict = None
+ def __init__(self, value):
+ self.value = value
+
def __hash__(self):
# hash collision!
return 1
def __eq__(self, other):
- if self.mutate_dict:
- self.mutate_dict[self] = 1
- return self == other
-
- d = {}
- d[NastyKey()] = 0
- NastyKey.mutate_dict = d
- with self.assertRaises(RuntimeError):
- d[NastyKey()] = None
+ if NastyKey.mutate_dict:
+ mydict, key = NastyKey.mutate_dict
+ NastyKey.mutate_dict = None
+ del mydict[key]
+ return self.value == other.value
+
+ key1 = NastyKey(1)
+ key2 = NastyKey(2)
+ d = {key1: 1}
+ NastyKey.mutate_dict = (d, key1)
+ with self.assertRaisesRegex(RuntimeError,
+ 'dictionary changed size during lookup'):
+ d[key2] = 2
def test_repr(self):
d = {}