summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-05-27 14:19:55 (GMT)
committerGitHub <noreply@github.com>2017-05-27 14:19:55 (GMT)
commit1626a479e22db3d44bcd6736d571243433cb6d0e (patch)
tree8cf90a3a5e48139c33497685ca661a17eb7bd6fb /Lib/test/test_random.py
parent96f502059717a692ca3abd968b26c5ea2918ad3a (diff)
downloadcpython-1626a479e22db3d44bcd6736d571243433cb6d0e.zip
cpython-1626a479e22db3d44bcd6736d571243433cb6d0e.tar.gz
cpython-1626a479e22db3d44bcd6736d571243433cb6d0e.tar.bz2
[2.7] bpo-29960 _random.Random corrupted on exception in setstate(). … (#1289)
(cherry picked from commit 9616a82e7802241a4b74cf7ae38d43c37bf66e48)
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 e4876fd..90d334a 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -311,6 +311,7 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
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
@@ -324,6 +325,10 @@ class MersenneTwister_TestBasicOps(TestBasicOps):
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)
def test_referenceImplementation(self):
# Compare the python implementation with results from the original