mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-36060: Document how collections.ChainMap() determines iteration order (GH-11969)
This commit is contained in:
parent
7463884f69
commit
86f093f71a
2 changed files with 29 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue