diff options
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r-- | Lib/test/test_dict.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 13be857..5b51376 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -1312,6 +1312,31 @@ class DictTest(unittest.TestCase): self.assertEqual(list(r), list('dcba')) self.assertRaises(StopIteration, next, r) + def test_reverse_iterator_for_empty_dict(self): + # bpo-38525: revered iterator should work properly + + # empty dict is directly used for reference count test + self.assertEqual(list(reversed({})), []) + self.assertEqual(list(reversed({}.items())), []) + self.assertEqual(list(reversed({}.values())), []) + self.assertEqual(list(reversed({}.keys())), []) + + # dict() and {} don't trigger the same code path + self.assertEqual(list(reversed(dict())), []) + self.assertEqual(list(reversed(dict().items())), []) + self.assertEqual(list(reversed(dict().values())), []) + self.assertEqual(list(reversed(dict().keys())), []) + + def test_reverse_iterator_for_shared_shared_dicts(self): + class A: + def __init__(self, x, y): + if x: self.x = x + if y: self.y = y + + self.assertEqual(list(reversed(A(1, 2).__dict__)), ['y', 'x']) + self.assertEqual(list(reversed(A(1, 0).__dict__)), ['x']) + self.assertEqual(list(reversed(A(0, 1).__dict__)), ['y']) + def test_dict_copy_order(self): # bpo-34320 od = collections.OrderedDict([('a', 1), ('b', 2)]) |