diff options
author | Guido van Rossum <guido@python.org> | 2003-01-29 17:58:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-01-29 17:58:45 (GMT) |
commit | 5d9113d8be81596bc93f2b1a37f57e5110d39a77 (patch) | |
tree | f7bdf7fc9aa5afbf967e9e110baea0e4cdd9ffec /Lib/test/pickletester.py | |
parent | d3590f937f4493445beeb253e5048771d1663ab7 (diff) | |
download | cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.zip cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.gz cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.bz2 |
Implement appropriate __getnewargs__ for all immutable subclassable builtin
types. The special handling for these can now be removed from save_newobj().
Add some testing for this.
Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
Diffstat (limited to 'Lib/test/pickletester.py')
-rw-r--r-- | Lib/test/pickletester.py | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 33b96e5..ed0e436 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -324,6 +324,21 @@ class AbstractPickleTests(unittest.TestCase): ## print ## pickletools.dis(s) + def test_newobj_generic(self): + for proto in [0, 1, 2]: + for C in myclasses: + B = C.__base__ + x = C(C.sample) + x.foo = 42 + s = self.dumps(x, proto) +## import pickletools +## print +## pickletools.dis(s) + y = self.loads(s) + detail = (proto, C, B, x, y, type(y)) + self.assertEqual(B(x), B(y), detail) + self.assertEqual(x.__dict__, y.__dict__, detail) + # XXX Temporary hack, so long as the C implementation of pickle protocol # XXX 2 isn't ready. When it is, move the methods in TempAbstractPickleTests # XXX into AbstractPickleTests above, and get rid of TempAbstractPickleTests @@ -405,11 +420,38 @@ class TempAbstractPickleTests(unittest.TestCase): finally: copy_reg.remove_extension(__name__, "MyList", 0xfffff0) +class MyInt(int): + sample = 1 + +class MyLong(long): + sample = 1L + +class MyFloat(float): + sample = 1.0 + +class MyComplex(complex): + sample = 1.0 + 0.0j + +class MyStr(str): + sample = "hello" + +class MyUnicode(unicode): + sample = u"hello \u1234" + class MyTuple(tuple): - pass + sample = (1, 2, 3) class MyList(list): - pass + sample = [1, 2, 3] + +class MyDict(dict): + sample = {"a": 1, "b": 2} + +myclasses = [MyInt, MyLong, MyFloat, + # MyComplex, # XXX complex somehow doesn't work here :-( + MyStr, MyUnicode, + MyTuple, MyList, MyDict] + class SlotList(MyList): __slots__ = ["foo"] |