summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_random.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-06-24 20:29:04 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-06-24 20:29:04 (GMT)
commit5f078ff7f0c6bb5086fae077379fc79729c34d2d (patch)
tree77471542e4966c70b2076b500f53014f3afc6d5d /Lib/test/test_random.py
parent663219a8cc0501791c45aa18986770c38c6430da (diff)
downloadcpython-5f078ff7f0c6bb5086fae077379fc79729c34d2d.zip
cpython-5f078ff7f0c6bb5086fae077379fc79729c34d2d.tar.gz
cpython-5f078ff7f0c6bb5086fae077379fc79729c34d2d.tar.bz2
SF bug #759889: Pickling of Random is broken
* Implement __reduce__() to support pickling. * Add a test case to prove a successful roundtrip through pickle.
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r--Lib/test/test_random.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 970b862..ea2243d 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -3,6 +3,7 @@
import unittest
import random
import time
+import pickle
from math import log, exp, sqrt, pi
from sets import Set
from test import test_support
@@ -102,6 +103,12 @@ class TestBasicOps(unittest.TestCase):
self.assertEqual(x1, x2)
self.assertEqual(y1, y2)
+ def test_pickling(self):
+ state = pickle.dumps(self.gen)
+ origseq = [self.gen.random() for i in xrange(10)]
+ newgen = pickle.loads(state)
+ restoredseq = [newgen.random() for i in xrange(10)]
+ self.assertEqual(origseq, restoredseq)
class WichmannHill_TestBasicOps(TestBasicOps):
gen = random.WichmannHill()