summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMariatta <Mariatta@users.noreply.github.com>2017-05-27 14:19:40 (GMT)
committerGitHub <noreply@github.com>2017-05-27 14:19:40 (GMT)
commit440bc4f4b2690b99541e87bedfdb0dc4abbc0501 (patch)
tree434a113097f34f7db6c92c7ff3d0a47cb760aab5 /Lib/test
parenta815b5a100f38b883b08d39567c5557de2c19a53 (diff)
downloadcpython-440bc4f4b2690b99541e87bedfdb0dc4abbc0501.zip
cpython-440bc4f4b2690b99541e87bedfdb0dc4abbc0501.tar.gz
cpython-440bc4f4b2690b99541e87bedfdb0dc4abbc0501.tar.bz2
[3.5] bpo-29960 _random.Random corrupted on exception in setstate(). … (#1288)
(cherry picked from commit 9616a82e7802241a4b74cf7ae38d43c37bf66e48)
Diffstat (limited to 'Lib/test')
-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 e80ed17..83a663f 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -348,6 +348,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
@@ -361,6 +362,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