mirror of https://github.com/python/cpython.git
gh-94808: Coverage: Check picklablability of calliter (GH-95923)
(cherry picked from commit cfbc7dd910
)
Co-authored-by: Michael Droettboom <mdboom@gmail.com>
This commit is contained in:
parent
4d4b1e6c0b
commit
fe99b64bef
|
@ -81,6 +81,16 @@ class BadIterableClass:
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
raise ZeroDivisionError
|
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
|
# Main test suite
|
||||||
|
|
||||||
class TestCase(unittest.TestCase):
|
class TestCase(unittest.TestCase):
|
||||||
|
@ -237,16 +247,7 @@ def __iter__(self):
|
||||||
|
|
||||||
# Test two-argument iter() with callable instance
|
# Test two-argument iter() with callable instance
|
||||||
def test_iter_callable(self):
|
def test_iter_callable(self):
|
||||||
class C:
|
self.check_iterator(iter(CallableIterClass(), 10), list(range(10)), pickle=True)
|
||||||
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)
|
|
||||||
|
|
||||||
# Test two-argument iter() with function
|
# Test two-argument iter() with function
|
||||||
def test_iter_function(self):
|
def test_iter_function(self):
|
||||||
|
|
Loading…
Reference in New Issue