Ensure ordered set is pickleable
Since the existing set and frozen sets are pickleable so should this type so that it functions and matches how the the existing types work. Change-Id: I6994b868ecbf0428ab4bc8ab5c2f4486ad53fb49
This commit is contained in:
@@ -18,6 +18,7 @@ import time
|
|||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import six
|
import six
|
||||||
|
from six.moves import cPickle as pickle
|
||||||
|
|
||||||
from taskflow import exceptions as excp
|
from taskflow import exceptions as excp
|
||||||
from taskflow import test
|
from taskflow import test
|
||||||
@@ -498,6 +499,15 @@ class FSMTest(test.TestCase):
|
|||||||
|
|
||||||
class OrderedSetTest(test.TestCase):
|
class OrderedSetTest(test.TestCase):
|
||||||
|
|
||||||
|
def test_pickleable(self):
|
||||||
|
items = [10, 9, 8, 7]
|
||||||
|
s = sets.OrderedSet(items)
|
||||||
|
self.assertEqual(items, list(s))
|
||||||
|
s_bin = pickle.dumps(s)
|
||||||
|
s2 = pickle.loads(s_bin)
|
||||||
|
self.assertEqual(s, s2)
|
||||||
|
self.assertEqual(items, list(s2))
|
||||||
|
|
||||||
def test_retain_ordering(self):
|
def test_retain_ordering(self):
|
||||||
items = [10, 9, 8, 7]
|
items = [10, 9, 8, 7]
|
||||||
s = sets.OrderedSet(iter(items))
|
s = sets.OrderedSet(iter(items))
|
||||||
|
|||||||
@@ -66,6 +66,12 @@ class OrderedSet(collections.Set, collections.Hashable):
|
|||||||
for value in six.iterkeys(self._data):
|
for value in six.iterkeys(self._data):
|
||||||
yield value
|
yield value
|
||||||
|
|
||||||
|
def __setstate__(self, items):
|
||||||
|
self.__init__(iterable=iter(items))
|
||||||
|
|
||||||
|
def __getstate__(self):
|
||||||
|
return tuple(self)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "%s(%s)" % (type(self).__name__, list(self))
|
return "%s(%s)" % (type(self).__name__, list(self))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user