summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorbladebryan <bryan.olson@acm.org>2017-04-22 06:10:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-04-22 06:10:46 (GMT)
commit9616a82e7802241a4b74cf7ae38d43c37bf66e48 (patch)
tree58586d87ce8abae757b2452074e4f71df6329ec5 /Lib/test/test_random.py
parent1a5856bf9295fa73995898d576e0bedf016aee1f (diff)
downloadcpython-9616a82e7802241a4b74cf7ae38d43c37bf66e48.zip
cpython-9616a82e7802241a4b74cf7ae38d43c37bf66e48.tar.gz
cpython-9616a82e7802241a4b74cf7ae38d43c37bf66e48.tar.bz2
bpo-29960 _random.Random corrupted on exception in setstate(). (#1019)
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 78909dd..48077fb 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -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