summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dictviews.py
diff options
context:
space:
mode:
authorForest Gregg <fgregg@users.noreply.github.com>2019-08-26 07:17:43 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-26 07:17:43 (GMT)
commit998cf1f03a61de8a0cd3811faa97973d4022bc55 (patch)
tree1536d878a50a5b365154b72d15d88c805773326f /Lib/test/test_dictviews.py
parentc3ea41e9bf100a5396b851488c3efe208e5e2179 (diff)
downloadcpython-998cf1f03a61de8a0cd3811faa97973d4022bc55.zip
cpython-998cf1f03a61de8a0cd3811faa97973d4022bc55.tar.gz
cpython-998cf1f03a61de8a0cd3811faa97973d4022bc55.tar.bz2
bpo-27575: port set intersection logic into dictview intersection (GH-7696)
Diffstat (limited to 'Lib/test/test_dictviews.py')
-rw-r--r--Lib/test/test_dictviews.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 2763cbf..b15cfeb 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -92,6 +92,12 @@ class DictSetTest(unittest.TestCase):
d1 = {'a': 1, 'b': 2}
d2 = {'b': 3, 'c': 2}
d3 = {'d': 4, 'e': 5}
+ d4 = {'d': 4}
+
+ class CustomSet(set):
+ def intersection(self, other):
+ return CustomSet(super().intersection(other))
+
self.assertEqual(d1.keys() & d1.keys(), {'a', 'b'})
self.assertEqual(d1.keys() & d2.keys(), {'b'})
self.assertEqual(d1.keys() & d3.keys(), set())
@@ -99,6 +105,14 @@ class DictSetTest(unittest.TestCase):
self.assertEqual(d1.keys() & set(d2.keys()), {'b'})
self.assertEqual(d1.keys() & set(d3.keys()), set())
self.assertEqual(d1.keys() & tuple(d1.keys()), {'a', 'b'})
+ self.assertEqual(d3.keys() & d4.keys(), {'d'})
+ self.assertEqual(d4.keys() & d3.keys(), {'d'})
+ self.assertEqual(d4.keys() & set(d3.keys()), {'d'})
+ self.assertIsInstance(d4.keys() & frozenset(d3.keys()), set)
+ self.assertIsInstance(frozenset(d3.keys()) & d4.keys(), set)
+ self.assertIs(type(d4.keys() & CustomSet(d3.keys())), set)
+ self.assertIs(type(d1.keys() & []), set)
+ self.assertIs(type([] & d1.keys()), set)
self.assertEqual(d1.keys() | d1.keys(), {'a', 'b'})
self.assertEqual(d1.keys() | d2.keys(), {'a', 'b', 'c'})