Issue #24620: Random.setstate() now validates the value of state last element.

This commit is contained in:
Serhiy Storchaka 2015-07-24 09:02:53 +03:00
parent f79dfe3f25
commit 178f0b6ddc
3 changed files with 11 additions and 0 deletions

View file

@ -338,6 +338,11 @@ class MersenneTwister_TestBasicOps(TestBasicOps, unittest.TestCase):
self.assertRaises(TypeError, self.gen.setstate, (2, ('a',)*625, None))
# Last element s/b an int also
self.assertRaises(TypeError, self.gen.setstate, (2, (0,)*624+('a',), None))
# Last element s/b between 0 and 624
with self.assertRaises((ValueError, OverflowError)):
self.gen.setstate((2, (1,)*624+(625,), None))
with self.assertRaises((ValueError, OverflowError)):
self.gen.setstate((2, (1,)*624+(-1,), None))
# 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