mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Made queue pickle-able.
This commit is contained in:
parent
6d3c060208
commit
ec88721cb2
@ -205,6 +205,15 @@ class queue(dict):
|
||||
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):
|
||||
"""Define .iteritems() in a class and subclass this to get the other iters.
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user