Skip to content

Commit 3133f66

Browse files
Add explicit tests for __setstate__.
1 parent 214f204 commit 3133f66

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Lib/test/test_range.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,20 @@ def test_iterator_unpickle_compat(self):
450450
it = pickle.loads(t)
451451
self.assertEqual(list(it), [14, 16, 18])
452452

453+
def test_iterator_setstate(self):
454+
it = iter(range(10, 20, 2))
455+
it.__setstate__(2)
456+
self.assertEqual(list(it), [14, 16, 18])
457+
it = reversed(range(10, 20, 2))
458+
it.__setstate__(3)
459+
self.assertEqual(list(it), [12, 10])
460+
it = iter(range(-2**65, 20, 2))
461+
it.__setstate__(2**64 + 7)
462+
self.assertEqual(list(it), [14, 16, 18])
463+
it = reversed(range(10, 2**65, 2))
464+
it.__setstate__(2**64 - 7)
465+
self.assertEqual(list(it), [12, 10])
466+
453467
def test_odd_bug(self):
454468
# This used to raise a "SystemError: NULL result without error"
455469
# because the range validation step was eating the exception

0 commit comments

Comments
 (0)