self.failUnless(issubclass(Exception, object))
def verify_instance_interface(self, ins):
- for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
+ for attr in ("args", "message", "__str__", "__repr__"):
self.failUnless(hasattr(ins, attr), "%s missing %s attribute" %
(ins.__class__.__name__, attr))
inheritance_tree.close()
self.failUnlessEqual(len(exc_set), 0, "%s not accounted for" % exc_set)
- interface_tests = ("length", "args", "message", "str", "unicode", "repr",
- "indexing")
+ interface_tests = ("length", "args", "message", "str", "unicode", "repr")
def interface_test_driver(self, results):
for test_name, (given, expected) in zip(self.interface_tests, results):
exc = Exception(arg)
results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg],
[str(exc), str(arg)], [unicode(exc), unicode(arg)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0], arg])
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)])
self.interface_test_driver(results)
def test_interface_multi_arg(self):
results = ([len(exc.args), arg_count], [exc.args, args],
[exc.message, ''], [str(exc), str(args)],
[unicode(exc), unicode(args)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)],
- [exc[-1], args[-1]])
+ [repr(exc), exc.__class__.__name__ + repr(exc.args)])
self.interface_test_driver(results)
def test_interface_no_arg(self):
exc = Exception()
results = ([len(exc.args), 0], [exc.args, tuple()], [exc.message, ''],
[str(exc), ''], [unicode(exc), u''],
- [repr(exc), exc.__class__.__name__ + '()'], [True, True])
+ [repr(exc), exc.__class__.__name__ + '()'])
self.interface_test_driver(results)
class UsageTests(unittest.TestCase):
self.catch_fails(NonBaseException)
self.catch_fails(NonBaseException())
+ def test_catch_BaseException_instance(self):
+ # Catching an instance of a BaseException subclass won't work.
+ self.catch_fails(BaseException())
+
def test_catch_string(self):
# Catching a string is bad.
self.catch_fails("spam")
};
-
-static PyObject *
-BaseException_getitem(PyBaseExceptionObject *self, Py_ssize_t index)
-{
- return PySequence_GetItem(self->args, index);
-}
-
-static PyObject *
-BaseException_getslice(PyBaseExceptionObject *self,
- Py_ssize_t start, Py_ssize_t stop)
-{
- return PySequence_GetSlice(self->args, start, stop);
-}
-
-static PySequenceMethods BaseException_as_sequence = {
- 0, /* sq_length; */
- 0, /* sq_concat; */
- 0, /* sq_repeat; */
- (ssizeargfunc)BaseException_getitem, /* sq_item; */
- (ssizessizeargfunc)BaseException_getslice, /* sq_slice; */
- 0, /* sq_ass_item; */
- 0, /* sq_ass_slice; */
- 0, /* sq_contains; */
- 0, /* sq_inplace_concat; */
- 0 /* sq_inplace_repeat; */
-};
-
static PyMemberDef BaseException_members[] = {
{"message", T_OBJECT, offsetof(PyBaseExceptionObject, message), 0,
PyDoc_STR("exception message")},
0, /* tp_compare; */
(reprfunc)BaseException_repr, /*tp_repr*/
0, /*tp_as_number*/
- &BaseException_as_sequence, /*tp_as_sequence*/
+ 0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/