Made queue pickle-able.

This commit is contained in:
Jeremy Fincher 2003-04-05 14:00:40 +00:00
parent 6d3c060208
commit ec88721cb2
2 changed files with 15 additions and 1 deletions

View File

@ -204,6 +204,15 @@ class queue(dict):
dict.__setitem__(self, i+self.last, v)
except KeyError:
raise IndexError, i
def __getstate__(self):
return (self.first, self.last, dict(self))
def __setstate__(self, (first, last, d)):
self.first = first
self.last = last
for (k, v) in d.iteritems():
dict.__setitem__(self, k, v)
class IterableMap(object):

View File

@ -33,6 +33,8 @@ from __future__ import generators
from test import *
import pickle
class QueueTest(unittest.TestCase):
def testGetitem(self):
q = queue()
@ -47,7 +49,6 @@ class QueueTest(unittest.TestCase):
self.assertRaises(IndexError, q.__getitem__, n)
#self.assertEqual(q[3:7], queue([3, 4, 5, 6]))
def testSetitem(self):
q1 = queue()
for i in xrange(10):
@ -178,6 +179,10 @@ class QueueTest(unittest.TestCase):
for _ in queue():
self.fail('no elements should be in empty queue')
def testPickleCopy(self):
q = queue(range(10))
self.assertEqual(q, pickle.loads(pickle.dumps(q)))
class FunctionsTest(unittest.TestCase):
def testCatch(self):