summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-02-21 17:12:15 (GMT)
committerGitHub <noreply@github.com>2019-02-21 17:12:15 (GMT)
commit86f093f71a594dcaf21b67ba13dda72863e9bde9 (patch)
tree8e6334a7628080757c21ea0d9aa855e16bf22836 /Lib
parent7463884f6993edcd92bec56213ee1959034fd31c (diff)
downloadcpython-86f093f71a594dcaf21b67ba13dda72863e9bde9.zip
cpython-86f093f71a594dcaf21b67ba13dda72863e9bde9.tar.gz
cpython-86f093f71a594dcaf21b67ba13dda72863e9bde9.tar.bz2
bpo-36060: Document how collections.ChainMap() determines iteration order (GH-11969)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_collections.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 74372d2..2d5a266 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -113,6 +113,20 @@ class TestChainMap(unittest.TestCase):
self.assertEqual(f['b'], 5) # find first in chain
self.assertEqual(f.parents['b'], 2) # look beyond maps[0]
+ def test_ordering(self):
+ # Combined order matches a series of dict updates from last to first.
+ # This test relies on the ordering of the underlying dicts.
+
+ baseline = {'music': 'bach', 'art': 'rembrandt'}
+ adjustments = {'art': 'van gogh', 'opera': 'carmen'}
+
+ cm = ChainMap(adjustments, baseline)
+
+ combined = baseline.copy()
+ combined.update(adjustments)
+
+ self.assertEqual(list(combined.items()), list(cm.items()))
+
def test_constructor(self):
self.assertEqual(ChainMap().maps, [{}]) # no-args --> one new dict
self.assertEqual(ChainMap({1:2}).maps, [{1:2}]) # 1 arg --> list