Skip to content

Commit

Permalink
Added test demonstrating failing case where subclass of list cannot b…
Browse files Browse the repository at this point in the history
…e pickled if it has a custom __init__.
  • Loading branch information
jaraco committed Apr 24, 2011
1 parent a7aa718 commit 6068c87
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tests/jsonpickle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from jsonpickle import handlers
from jsonpickle import tags

from samples import Thing, ThingWithSlots, ThingWithProps, BrokenReprThing, DictSubclass, ListSubclass, SetSubclass
from samples import Thing, ThingWithSlots, ThingWithProps, BrokenReprThing, DictSubclass, ListSubclass, SetSubclass, ListSubclassWithInit

class PicklingTestCase(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -437,6 +437,13 @@ def test_references(self):
for x in range(len(coll)):
self.assertEqual(repr(coll[x]), repr(inflated[x]))

def test_list_subclass_with_init(self):
obj = ListSubclassWithInit('foo')
self.assertEqual(obj.attr, 'foo')
flattened = self.pickler.flatten(obj)
inflated = self.unpickler.restore(flattened)
self.assertEqual(type(inflated), ListSubclassWithInit)

class JSONPickleTestCase(unittest.TestCase):
def setUp(self):
self.obj = Thing('A name')
Expand Down
4 changes: 4 additions & 0 deletions tests/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class DictSubclass(dict):
class ListSubclass(list):
pass

class ListSubclassWithInit(list):
def __init__(self, attr):
self.attr = attr
super(ListSubclassWithInit, self).__init__()

class SetSubclass(set):
pass
Expand Down

0 comments on commit 6068c87

Please sign in to comment.