diff options
| author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2018-02-11 08:30:31 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-11 08:30:31 (GMT) |
| commit | 3793f95f98c3112ce447288a5bf9899eb9e35423 (patch) | |
| tree | 7c7b62ce2d585c9ec90ed1b502dd4881bd37e739 /Lib/test/test_collections.py | |
| parent | 8d1f2f40389c476d9240ec87a33da0373597c6af (diff) | |
| download | cpython-3793f95f98c3112ce447288a5bf9899eb9e35423.zip cpython-3793f95f98c3112ce447288a5bf9899eb9e35423.tar.gz cpython-3793f95f98c3112ce447288a5bf9899eb9e35423.tar.bz2 | |
bpo-32792: Preserve mapping order in ChainMap() (GH-5586)
Diffstat (limited to 'Lib/test/test_collections.py')
| -rw-r--r-- | Lib/test/test_collections.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index a55239e..2099d23 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -141,6 +141,23 @@ class TestChainMap(unittest.TestCase): with self.assertRaises(KeyError): d.popitem() + def test_order_preservation(self): + d = ChainMap( + OrderedDict(j=0, h=88888), + OrderedDict(), + OrderedDict(i=9999, d=4444, c=3333), + OrderedDict(f=666, b=222, g=777, c=333, h=888), + OrderedDict(), + OrderedDict(e=55, b=22), + OrderedDict(a=1, b=2, c=3, d=4, e=5), + OrderedDict(), + ) + self.assertEqual(''.join(d), 'abcdefghij') + self.assertEqual(list(d.items()), + [('a', 1), ('b', 222), ('c', 3333), ('d', 4444), + ('e', 55), ('f', 666), ('g', 777), ('h', 88888), + ('i', 9999), ('j', 0)]) + def test_dict_coercion(self): d = ChainMap(dict(a=1, b=2), dict(b=20, c=30)) self.assertEqual(dict(d), dict(a=1, b=2, c=30)) |
