summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_operator.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-22 07:43:35 (GMT)
committerGitHub <noreply@github.com>2020-06-22 07:43:35 (GMT)
commitcafe1b6e9d3594a34aba50e872d4198296ffaadf (patch)
tree4508274bc56f2a9fe7caef1f61dbdae524a157be /Lib/test/test_operator.py
parent4901ea952691ad70aae21cfe04b6bd363b5a6aff (diff)
downloadcpython-cafe1b6e9d3594a34aba50e872d4198296ffaadf.zip
cpython-cafe1b6e9d3594a34aba50e872d4198296ffaadf.tar.gz
cpython-cafe1b6e9d3594a34aba50e872d4198296ffaadf.tar.bz2
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_operator.py')
-rw-r--r--Lib/test/test_operator.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index f46d94a..29f5e42 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -35,6 +35,10 @@ class Seq2(object):
def __rmul__(self, other):
return other * self.lst
+class BadIterable:
+ def __iter__(self):
+ raise ZeroDivisionError
+
class OperatorTestCase:
def test_lt(self):
@@ -142,6 +146,7 @@ class OperatorTestCase:
operator = self.module
self.assertRaises(TypeError, operator.countOf)
self.assertRaises(TypeError, operator.countOf, None, None)
+ self.assertRaises(ZeroDivisionError, operator.countOf, BadIterable(), 1)
self.assertEqual(operator.countOf([1, 2, 1, 3, 1, 4], 3), 1)
self.assertEqual(operator.countOf([1, 2, 1, 3, 1, 4], 5), 0)
@@ -176,6 +181,7 @@ class OperatorTestCase:
operator = self.module
self.assertRaises(TypeError, operator.indexOf)
self.assertRaises(TypeError, operator.indexOf, None, None)
+ self.assertRaises(ZeroDivisionError, operator.indexOf, BadIterable(), 1)
self.assertEqual(operator.indexOf([4, 3, 2, 1], 3), 1)
self.assertRaises(ValueError, operator.indexOf, [4, 3, 2, 1], 0)
@@ -258,6 +264,7 @@ class OperatorTestCase:
operator = self.module
self.assertRaises(TypeError, operator.contains)
self.assertRaises(TypeError, operator.contains, None, None)
+ self.assertRaises(ZeroDivisionError, operator.contains, BadIterable(), 1)
self.assertTrue(operator.contains(range(4), 2))
self.assertFalse(operator.contains(range(4), 5))