diff options
author | Guido van Rossum <guido@python.org> | 2003-01-28 17:55:05 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-01-28 17:55:05 (GMT) |
commit | 533dbcf250bf4e2310ab72d8d42f2efe3be6febf (patch) | |
tree | 49c338482d819fdd1f4027ef590529986b2070f9 /Lib/test/pickletester.py | |
parent | 53b39d2e70768e34c3f01f0d6efbe76c9913d422 (diff) | |
download | cpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.zip cpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.tar.gz cpython-533dbcf250bf4e2310ab72d8d42f2efe3be6febf.tar.bz2 |
Some experimental support for generating NEWOBJ with proto=2, and
fixed a bug in load_newobj().
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 3d65383..ea658bb 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -300,6 +300,45 @@ class AbstractPickleTests(unittest.TestCase): y = self.loads(s) self.assert_(x is y, (proto, x, s, y)) + def test_newobj_tuple(self): + x = MyTuple([1, 2, 3], foo=42, bar="hello") + s = self.dumps(x, 2) + y = self.loads(s) + self.assertEqual(tuple(x), tuple(y)) + self.assertEqual(x.__dict__, y.__dict__) + + def test_newobj_list(self): + x = MyList([1, 2, 3], foo=42, bar="hello") + s = self.dumps(x, 2) + y = self.loads(s) + self.assertEqual(list(x), list(y)) + self.assertEqual(x.__dict__, y.__dict__) + +class MyTuple(tuple): + def __new__(cls, *args, **kwds): + # Ignore **kwds + return tuple.__new__(cls, *args) + def __getnewargs__(self): + return (tuple(self),) + def __init__(self, *args, **kwds): + for k, v in kwds.items(): + setattr(self, k, v) + +class MyList(list): + def __new__(cls, *args, **kwds): + # Ignore **kwds + return list.__new__(cls, *args) + def __init__(self, *args, **kwds): + for k, v in kwds.items(): + setattr(self, k, v) + def __getstate__(self): + return list(self), self.__dict__ + def __setstate__(self, arg): + lst, dct = arg + for x in lst: + self.append(x) + self.__init__(**dct) + class AbstractPickleModuleTests(unittest.TestCase): def test_dump_closed_file(self): |