summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2005-03-11 06:49:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2005-03-11 06:49:40 (GMT)
commit96229b191814556622b575fd320e822f918f355a (patch)
tree3804d604b12aea8ea55a14816c853e9c130fc0ca /Lib
parent26e512a04f7b68684503d7afe21154b5dd392d6e (diff)
downloadcpython-96229b191814556622b575fd320e822f918f355a.zip
cpython-96229b191814556622b575fd320e822f918f355a.tar.gz
cpython-96229b191814556622b575fd320e822f918f355a.tar.bz2
Add two new functions, any() and all().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_builtin.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index 5aa9197..4e8ffe5 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -92,6 +92,14 @@ if have_unicode:
(unichr(0x200), ValueError),
]
+class TestFailingBool:
+ def __nonzero__(self):
+ raise RuntimeError
+
+class TestFailingIter:
+ def __iter__(self):
+ raise RuntimeError
+
class BuiltinTest(unittest.TestCase):
def test_import(self):
@@ -117,6 +125,34 @@ class BuiltinTest(unittest.TestCase):
# str
self.assertRaises(TypeError, abs, 'a')
+ def test_all(self):
+ self.assertEqual(all([2, 4, 6]), True)
+ self.assertEqual(all([2, None, 6]), False)
+ self.assertRaises(RuntimeError, all, [2, TestFailingBool(), 6])
+ self.assertRaises(RuntimeError, all, TestFailingIter())
+ self.assertRaises(TypeError, all, 10) # Non-iterable
+ self.assertRaises(TypeError, all) # No args
+ self.assertRaises(TypeError, all, [2, 4, 6], []) # Too many args
+ self.assertEqual(all([]), True) # Empty iterator
+ S = [50, 60]
+ self.assertEqual(all(x > 42 for x in S), True)
+ S = [50, 40, 60]
+ self.assertEqual(all(x > 42 for x in S), False)
+
+ def test_any(self):
+ self.assertEqual(any([None, None, None]), False)
+ self.assertEqual(any([None, 4, None]), True)
+ self.assertRaises(RuntimeError, any, [None, TestFailingBool(), 6])
+ self.assertRaises(RuntimeError, all, TestFailingIter())
+ self.assertRaises(TypeError, any, 10) # Non-iterable
+ self.assertRaises(TypeError, any) # No args
+ self.assertRaises(TypeError, any, [2, 4, 6], []) # Too many args
+ self.assertEqual(any([]), False) # Empty iterator
+ S = [40, 60, 30]
+ self.assertEqual(any(x > 42 for x in S), True)
+ S = [10, 20, 30]
+ self.assertEqual(any(x > 42 for x in S), False)
+
def test_apply(self):
def f0(*args):
self.assertEqual(args, ())