summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-02-13 18:42:00 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-02-13 18:42:00 (GMT)
commite9ef203ea69d64b2bdaae4ebbb79e46716cd437d (patch)
treecd937511d1b04c59035b6367b80ae6df91a89992
parentc1eea67d9384f25febfe03437db426c0062f4c1d (diff)
downloadcpython-e9ef203ea69d64b2bdaae4ebbb79e46716cd437d.zip
cpython-e9ef203ea69d64b2bdaae4ebbb79e46716cd437d.tar.gz
cpython-e9ef203ea69d64b2bdaae4ebbb79e46716cd437d.tar.bz2
Added a simple NEWOBJ test. This is in the pickle-only part of the
test for now (cPickle can't yet produce NEWOBJ).
-rw-r--r--Lib/test/pickletester.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py
index 8479d43..c6ffbea 100644
--- a/Lib/test/pickletester.py
+++ b/Lib/test/pickletester.py
@@ -724,6 +724,16 @@ class AbstractPickleTests(unittest.TestCase):
# XXX along with the references to it in test_pickle.py.
class TempAbstractPickleTests(unittest.TestCase):
+ def test_simple_newobj(self):
+ x = object.__new__(SimpleNewObj) # avoid __init__
+ x.abc = 666
+ for proto in protocols:
+ s = self.dumps(x, proto)
+ self.assertEqual(opcode_in_pickle(pickle.NEWOBJ, s), proto >= 2)
+ y = self.loads(s) # will raise TypeError if __init__ called
+ self.assertEqual(y.abc, 666)
+ self.assertEqual(x.__dict__, y.__dict__)
+
def test_newobj_list_slots(self):
x = SlotList([1, 2, 3])
x.foo = 42
@@ -771,6 +781,11 @@ myclasses = [MyInt, MyLong, MyFloat,
class SlotList(MyList):
__slots__ = ["foo"]
+class SimpleNewObj(object):
+ def __init__(self, a, b, c):
+ # raise an error, to make sure this isn't called
+ raise TypeError("SimpleNewObj.__init__() didn't expect to get called")
+
class AbstractPickleModuleTests(unittest.TestCase):
def test_dump_closed_file(self):