y = self.loads(s)
self.assertEqual(y._reduce_called, 1)
+ def test_bad_getattr(self):
+ x = BadGetattr()
+ for proto in 0, 1:
+ self.assertRaises(RuntimeError, self.dumps, x, proto)
+ # protocol 2 don't raise a RuntimeError.
+ d = self.dumps(x, 2)
+ self.assertRaises(RuntimeError, self.loads, d)
+
# Test classes for reduce_ex
class REX_one(object):
# raise an error, to make sure this isn't called
raise TypeError("SimpleNewObj.__init__() didn't expect to get called")
+class BadGetattr:
+ def __getattr__(self, key):
+ self.foo
+
class AbstractPickleModuleTests(unittest.TestCase):
def test_dump_closed_file(self):
inst = self->stack->data[self->stack->length - 1];
setstate = PyObject_GetAttrString(inst, "__setstate__");
- if (setstate == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
- PyErr_Clear();
+ if (setstate == NULL) {
+ if (PyErr_ExceptionMatches(PyExc_AttributeError))
+ PyErr_Clear();
+ else
+ return -1;
}
else {
PyObject *result;