summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2020-06-12 17:19:25 (GMT)
committerGitHub <noreply@github.com>2020-06-12 17:19:25 (GMT)
commit3ee0e48b0376a710c08eec6f30e4181563b192a2 (patch)
tree8a0ea5514e2b1bfb3617f434271c85465d805463 /Lib/test/test_dict.py
parent0d3350daa8123a3e16d4a534b6e873eb12c10d7c (diff)
downloadcpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.zip
cpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.tar.gz
cpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.tar.bz2
bpo-40890: Add `mapping` property to dict views (GH-20749)
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index 5c08810..9ff8b7d 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -105,6 +105,26 @@ class DictTest(unittest.TestCase):
self.assertRaises(TypeError, d.items, None)
self.assertEqual(repr(dict(a=1).items()), "dict_items([('a', 1)])")
+ def test_views_mapping(self):
+ mappingproxy = type(type.__dict__)
+ class Dict(dict):
+ pass
+ for cls in [dict, Dict]:
+ d = cls()
+ m1 = d.keys().mapping
+ m2 = d.values().mapping
+ m3 = d.items().mapping
+
+ for m in [m1, m2, m3]:
+ self.assertIsInstance(m, mappingproxy)
+ self.assertEqual(m, d)
+
+ d["foo"] = "bar"
+
+ for m in [m1, m2, m3]:
+ self.assertIsInstance(m, mappingproxy)
+ self.assertEqual(m, d)
+
def test_contains(self):
d = {}
self.assertNotIn('a', d)