summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-02-10 18:55:06 (GMT)
committerGuido van Rossum <guido@python.org>2007-02-10 18:55:06 (GMT)
commit3ac6741f7922b7fdf05f9ba231c6eeff73580f8a (patch)
tree6d83c8b07925e43993c2d7c77bf648d1e31a6932 /Lib
parent83825acd1bd02148c75bd2f4469767d4839196d3 (diff)
downloadcpython-3ac6741f7922b7fdf05f9ba231c6eeff73580f8a.zip
cpython-3ac6741f7922b7fdf05f9ba231c6eeff73580f8a.tar.gz
cpython-3ac6741f7922b7fdf05f9ba231c6eeff73580f8a.tar.bz2
Implement __contains__ for dict_keys and dict_items.
(Not for dict_values, where it can't be done faster than the default implementation which just iterates the elements.)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_dictviews.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index c0c1da1..4c436f7 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -3,17 +3,39 @@ from test import test_support
class DictSetTest(unittest.TestCase):
+ def test_constructors_not_callable(self):
+ kt = type({}.KEYS())
+ self.assertRaises(TypeError, kt, {})
+ self.assertRaises(TypeError, kt)
+ it = type({}.ITEMS())
+ self.assertRaises(TypeError, it, {})
+ self.assertRaises(TypeError, it)
+ vt = type({}.VALUES())
+ self.assertRaises(TypeError, vt, {})
+ self.assertRaises(TypeError, vt)
+
def test_dict_keys(self):
d = {1: 10, "a": "ABC"}
keys = d.KEYS()
self.assertEqual(set(keys), {1, "a"})
self.assertEqual(len(keys), 2)
+ self.assert_(1 in keys)
+ self.assert_("a" in keys)
+ self.assert_(10 not in keys)
+ self.assert_("Z" not in keys)
def test_dict_items(self):
d = {1: 10, "a": "ABC"}
items = d.ITEMS()
self.assertEqual(set(items), {(1, 10), ("a", "ABC")})
self.assertEqual(len(items), 2)
+ self.assert_((1, 10) in items)
+ self.assert_(("a", "ABC") in items)
+ self.assert_((1, 11) not in items)
+ self.assert_(1 not in items)
+ self.assert_(() not in items)
+ self.assert_((1,) not in items)
+ self.assert_((1, 2, 3) not in items)
def test_dict_values(self):
d = {1: 10, "a": "ABC"}