mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
SF bug #759889: Pickling of Random is broken
* Implement __reduce__() to support pickling. * Add a test case to prove a successful roundtrip through pickle.
This commit is contained in:
parent
663219a8cc
commit
5f078ff7f0
2 changed files with 10 additions and 0 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue