summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorDaniel Stutzbach <daniel@stutzbachenterprises.com>2010-09-02 15:06:06 (GMT)
committerDaniel Stutzbach <daniel@stutzbachenterprises.com>2010-09-02 15:06:06 (GMT)
commit045b3ba184f78a1ff0ca96561d8b5651c22233c0 (patch)
tree837b1fd156b77afa8cd44904bb1a9ce28be08df2 /Lib/test
parent928d4eeee8e92ca44899108e297437392102aaa4 (diff)
downloadcpython-045b3ba184f78a1ff0ca96561d8b5651c22233c0.zip
cpython-045b3ba184f78a1ff0ca96561d8b5651c22233c0.tar.gz
cpython-045b3ba184f78a1ff0ca96561d8b5651c22233c0.tar.bz2
Issue #9212: Added the missing isdisjoint method to the dict_keys and
dict_items views. The method is required by the collections.Set ABC, which the views register as supporting.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_dictviews.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 277e05b..4c04079 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -112,6 +112,24 @@ class DictSetTest(unittest.TestCase):
self.assertEqual(d1.keys() ^ set(d3.keys()),
{'a', 'b', 'd', 'e'})
+ self.assertFalse(d1.keys().isdisjoint(d1.keys()))
+ self.assertFalse(d1.keys().isdisjoint(d2.keys()))
+ self.assertFalse(d1.keys().isdisjoint(list(d2.keys())))
+ self.assertFalse(d1.keys().isdisjoint(set(d2.keys())))
+ self.assertTrue(d1.keys().isdisjoint({'x', 'y', 'z'}))
+ self.assertTrue(d1.keys().isdisjoint(['x', 'y', 'z']))
+ self.assertTrue(d1.keys().isdisjoint(set(['x', 'y', 'z'])))
+ self.assertTrue(d1.keys().isdisjoint(set(['x', 'y'])))
+ self.assertTrue(d1.keys().isdisjoint(['x', 'y']))
+ self.assertTrue(d1.keys().isdisjoint({}))
+ self.assertTrue(d1.keys().isdisjoint(d3.keys()))
+
+ de = {}
+ self.assertTrue(de.keys().isdisjoint(set()))
+ self.assertTrue(de.keys().isdisjoint([]))
+ self.assertTrue(de.keys().isdisjoint(de.keys()))
+ self.assertTrue(de.keys().isdisjoint([1]))
+
def test_items_set_operations(self):
d1 = {'a': 1, 'b': 2}
d2 = {'a': 2, 'b': 2}
@@ -144,6 +162,23 @@ class DictSetTest(unittest.TestCase):
self.assertEqual(d1.items() ^ d3.items(),
{('a', 1), ('b', 2), ('d', 4), ('e', 5)})
+ self.assertFalse(d1.items().isdisjoint(d1.items()))
+ self.assertFalse(d1.items().isdisjoint(d2.items()))
+ self.assertFalse(d1.items().isdisjoint(list(d2.items())))
+ self.assertFalse(d1.items().isdisjoint(set(d2.items())))
+ self.assertTrue(d1.items().isdisjoint({'x', 'y', 'z'}))
+ self.assertTrue(d1.items().isdisjoint(['x', 'y', 'z']))
+ self.assertTrue(d1.items().isdisjoint(set(['x', 'y', 'z'])))
+ self.assertTrue(d1.items().isdisjoint(set(['x', 'y'])))
+ self.assertTrue(d1.items().isdisjoint({}))
+ self.assertTrue(d1.items().isdisjoint(d3.items()))
+
+ de = {}
+ self.assertTrue(de.items().isdisjoint(set()))
+ self.assertTrue(de.items().isdisjoint([]))
+ self.assertTrue(de.items().isdisjoint(de.items()))
+ self.assertTrue(de.items().isdisjoint([1]))
+
def test_main():
support.run_unittest(DictSetTest)