diff options
author | Raymond Hettinger <python@rcn.com> | 2014-05-04 04:58:45 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2014-05-04 04:58:45 (GMT) |
commit | 53d2c41f77ab7658a1380bc304946b4920e5b49b (patch) | |
tree | 8bd81a22a224983b3376357c8afa0c6988244665 /Lib/test/test_collections.py | |
parent | 71ac07f8baf21bf7a116e97accc12804f1afcdd4 (diff) | |
download | cpython-53d2c41f77ab7658a1380bc304946b4920e5b49b.zip cpython-53d2c41f77ab7658a1380bc304946b4920e5b49b.tar.gz cpython-53d2c41f77ab7658a1380bc304946b4920e5b49b.tar.bz2 |
Issue #19414: Have the OrderedDict mark deleted links as unusable.
This gives an earlier and more visible failure if a link is deleted
during iteration.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index d352d2a..7e14980 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -1193,6 +1193,16 @@ class TestOrderedDict(unittest.TestCase): [t[1] for t in reversed(pairs)]) self.assertEqual(list(reversed(od.items())), list(reversed(pairs))) + def test_detect_deletion_during_iteration(self): + od = OrderedDict.fromkeys('abc') + it = iter(od) + key = next(it) + del od[key] + with self.assertRaises(Exception): + # Note, the exact exception raised is not guaranteed + # The only guarantee that the next() will not succeed + next(it) + def test_popitem(self): pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] shuffle(pairs) |