summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dict.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-24 23:41:22 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-24 23:41:22 (GMT)
commit523259ba072e91605a8be25360ec402dae74bb2f (patch)
tree037a97f20df2071171a297c0090d50bc27705f59 /Lib/test/test_dict.py
parenteb8b3a6d61860cdbf52af6e82b44925b81bb39b1 (diff)
downloadcpython-523259ba072e91605a8be25360ec402dae74bb2f.zip
cpython-523259ba072e91605a8be25360ec402dae74bb2f.tar.gz
cpython-523259ba072e91605a8be25360ec402dae74bb2f.tar.bz2
Keir Mierle's set operations for dict views (keys/items only of course).
Diffstat (limited to 'Lib/test/test_dict.py')
-rw-r--r--Lib/test/test_dict.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index d81ecf5..60f3f40 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -458,6 +458,23 @@ class DictTest(unittest.TestCase):
self.assertRaises(RuntimeError, lambda: d2.items() < d3.items())
self.assertRaises(RuntimeError, lambda: d3.items() > d2.items())
+ def test_dictview_set_operations(self):
+ k1 = {1:1, 2:2}.keys()
+ k2 = {1:1, 2:2, 3:3}.keys()
+ k3 = {4:4}.keys()
+
+ self.assertEquals(k1 - k2, set())
+ self.assertEquals(k1 - k3, {1,2})
+ self.assertEquals(k2 - k1, {3})
+ self.assertEquals(k3 - k1, {4})
+ self.assertEquals(k1 & k2, {1,2})
+ self.assertEquals(k1 & k3, set())
+ self.assertEquals(k1 | k2, {1,2,3})
+ self.assertEquals(k1 ^ k2, {3})
+ self.assertEquals(k1 ^ k3, {1,2,4})
+
+ # XXX similar tests for .items()
+
def test_missing(self):
# Make sure dict doesn't have a __missing__ method
self.assertEqual(hasattr(dict, "__missing__"), False)