Skip to content

Commit 76a0020

Browse files
authored
Merge pull request RustPython#940 from sanxiyn/test-all-any
Test all and any
2 parents 252ac4a + d3966af commit 76a0020

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

tests/snippets/builtin_all.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from testutils import assert_raises
2+
from testutils import TestFailingBool, TestFailingIter
3+
4+
assert all([True])
5+
assert not all([False])
6+
assert all([])
7+
assert not all([False, TestFailingBool()])
8+
9+
assert_raises(RuntimeError, lambda: all(TestFailingIter()))
10+
assert_raises(RuntimeError, lambda: all([TestFailingBool()]))

tests/snippets/builtin_any.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
assert any([1]);
2-
assert not any([]);
3-
assert not any([0,0,0,0]);
4-
assert any([0,0,1,0,0]);
5-
def anything(a):
6-
return a
1+
from testutils import assert_raises
2+
from testutils import TestFailingBool, TestFailingIter
73

8-
class Test:
9-
def __iter__(self):
10-
while True:
11-
yield True
4+
assert any([True])
5+
assert not any([False])
6+
assert not any([])
7+
assert any([True, TestFailingBool()])
128

13-
assert any(map(anything, Test()))
9+
assert_raises(RuntimeError, lambda: any(TestFailingIter()))
10+
assert_raises(RuntimeError, lambda: any([TestFailingBool()]))

tests/snippets/testutils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
3434
if not issubclass(exc_type, self.expected):
3535
return False
3636
return True
37+
38+
39+
class TestFailingBool:
40+
def __bool__(self):
41+
raise RuntimeError
42+
43+
class TestFailingIter:
44+
def __iter__(self):
45+
raise RuntimeError

0 commit comments

Comments
 (0)