summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2022-03-03 04:06:29 (GMT)
committerGitHub <noreply@github.com>2022-03-03 04:06:29 (GMT)
commit4f74052b455a54ac736f38973693aeea2ec14116 (patch)
treebaae7020b698b198f0e1bbb009d206601ba15247 /Lib/test/test_dict.py
parenta8c87a239ee1414d6dd0b062fe9ec3e5b0c50cb8 (diff)
downloadcpython-4f74052b455a54ac736f38973693aeea2ec14116.zip
cpython-4f74052b455a54ac736f38973693aeea2ec14116.tar.gz
cpython-4f74052b455a54ac736f38973693aeea2ec14116.tar.bz2
bpo-40116: dict: Add regression test for iteration order. (GH-31550)
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 66f5d56..e60ae43 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -1077,6 +1077,23 @@ class DictTest(unittest.TestCase):
self.assertEqual(list(a), ['x', 'y'])
self.assertEqual(list(b), ['x', 'y', 'z'])
+ @support.cpython_only
+ def test_splittable_update(self):
+ """dict.update(other) must preserve order in other."""
+ class C:
+ def __init__(self, order):
+ if order:
+ self.a, self.b, self.c = 1, 2, 3
+ else:
+ self.c, self.b, self.a = 1, 2, 3
+ o = C(True)
+ o = C(False) # o.__dict__ has reversed order.
+ self.assertEqual(list(o.__dict__), ["c", "b", "a"])
+
+ d = {}
+ d.update(o.__dict__)
+ self.assertEqual(list(d), ["c", "b", "a"])
+
def test_iterator_pickling(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
data = {1:"a", 2:"b", 3:"c"}