gh-94808: Coverage: Check picklablability of calliter (#95923)

This commit is contained in:
Michael Droettboom 2022-10-03 16:50:30 -04:00 committed by GitHub
parent 9302e331c7
commit cfbc7dd910
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,6 +81,16 @@ class BadIterableClass:
def __iter__(self):
raise ZeroDivisionError
class CallableIterClass:
def __init__(self):
self.i = 0
def __call__(self):
i = self.i
self.i = i + 1
if i > 100:
raise IndexError # Emergency stop
return i
# Main test suite
class TestCase(unittest.TestCase):
@ -237,16 +247,7 @@ class TestCase(unittest.TestCase):
# Test two-argument iter() with callable instance
def test_iter_callable(self):
class C:
def __init__(self):
self.i = 0
def __call__(self):
i = self.i
self.i = i + 1
if i > 100:
raise IndexError # Emergency stop
return i
self.check_iterator(iter(C(), 10), list(range(10)), pickle=False)
self.check_iterator(iter(CallableIterClass(), 10), list(range(10)), pickle=True)
# Test two-argument iter() with function
def test_iter_function(self):