Skip to content
Merged
Prev Previous commit
Next Next commit
Add explicit tests for __setstate__.
  • Loading branch information
serhiy-storchaka committed Aug 29, 2021
commit 3133f664f1cd7c04ae60c7ca51b6ea3224024ac9
14 changes: 14 additions & 0 deletions Lib/test/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,20 @@ def test_iterator_unpickle_compat(self):
it = pickle.loads(t)
self.assertEqual(list(it), [14, 16, 18])

def test_iterator_setstate(self):
it = iter(range(10, 20, 2))
it.__setstate__(2)
self.assertEqual(list(it), [14, 16, 18])
it = reversed(range(10, 20, 2))
it.__setstate__(3)
self.assertEqual(list(it), [12, 10])
it = iter(range(-2**65, 20, 2))
it.__setstate__(2**64 + 7)
self.assertEqual(list(it), [14, 16, 18])
it = reversed(range(10, 2**65, 2))
it.__setstate__(2**64 - 7)
self.assertEqual(list(it), [12, 10])

def test_odd_bug(self):
# This used to raise a "SystemError: NULL result without error"
# because the range validation step was eating the exception
Expand Down