summaryrefslogtreecommitdiff
path: root/Lib/test/test_iter.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-22 10:43:35 +0300
committerGitHub <noreply@github.com>2020-06-22 10:43:35 +0300
commitcafe1b6e9d3594a34aba50e872d4198296ffaadf (patch)
tree4508274bc56f2a9fe7caef1f61dbdae524a157be /Lib/test/test_iter.py
parent4901ea952691ad70aae21cfe04b6bd363b5a6aff (diff)
downloadcpython-git-cafe1b6e9d3594a34aba50e872d4198296ffaadf.tar.gz
bpo-40824: Do not mask errors in __iter__ in "in" and the operator module. (GH-20537)
Unexpected errors in calling the __iter__ method are no longer masked by TypeError in the "in" operator and functions operator.contains(), operator.indexOf() and operator.countOf().
Diffstat (limited to 'Lib/test/test_iter.py')
-rw-r--r--Lib/test/test_iter.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_iter.py b/Lib/test/test_iter.py
index 6aceda23e9..5243469398 100644
--- a/Lib/test/test_iter.py
+++ b/Lib/test/test_iter.py
@@ -76,6 +76,10 @@ class NoIterClass:
return i
__iter__ = None
+class BadIterableClass:
+ def __iter__(self):
+ raise ZeroDivisionError
+
# Main test suite
class TestCase(unittest.TestCase):
@@ -658,6 +662,7 @@ class TestCase(unittest.TestCase):
self.assertRaises(TypeError, lambda: 3 in 12)
self.assertRaises(TypeError, lambda: 3 not in map)
+ self.assertRaises(ZeroDivisionError, lambda: 3 in BadIterableClass())
d = {"one": 1, "two": 2, "three": 3, 1j: 2j}
for k in d:
@@ -740,6 +745,7 @@ class TestCase(unittest.TestCase):
self.assertRaises(TypeError, indexOf, 42, 1)
self.assertRaises(TypeError, indexOf, indexOf, indexOf)
+ self.assertRaises(ZeroDivisionError, indexOf, BadIterableClass(), 1)
f = open(TESTFN, "w")
try:
@@ -1027,6 +1033,7 @@ class TestCase(unittest.TestCase):
def test_error_iter(self):
for typ in (DefaultIterClass, NoIterClass):
self.assertRaises(TypeError, iter, typ())
+ self.assertRaises(ZeroDivisionError, iter, BadIterableClass())
def test_main():