mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-29960 _random.Random corrupted on exception in setstate(). (#1019)
This commit is contained in:
parent
1a5856bf92
commit
9616a82e78
4 changed files with 13 additions and 1 deletions
|
@ -423,6 +423,7 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
|
|||
self.assertRaises(ValueError, self.gen.setstate, (1, None, None))
|
||||
|
||||
def test_setstate_middle_arg(self):
|
||||
start_state = self.gen.getstate()
|
||||
# Wrong type, s/b tuple
|
||||
self.assertRaises(TypeError, self.gen.setstate, (2, None, None))
|
||||
# Wrong length, s/b 625
|
||||
|
@ -436,6 +437,10 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
|
|||
self.gen.setstate((2, (1,)*624+(625,), None))
|
||||
with self.assertRaises((ValueError, OverflowError)):
|
||||
self.gen.setstate((2, (1,)*624+(-1,), None))
|
||||
# Failed calls to setstate() should not have changed the state.
|
||||
bits100 = self.gen.getrandbits(100)
|
||||
self.gen.setstate(start_state)
|
||||
self.assertEqual(self.gen.getrandbits(100), bits100)
|
||||
|
||||
# Little trick to make "tuple(x % (2**32) for x in internalstate)"
|
||||
# raise ValueError. I cannot think of a simple way to achieve this, so
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue