Пример #1
0
def test_new_exception(space):
    w_error = new_exception_class(space, '_socket.error')
    assert w_error.getname(space) == u'error'
    assert space.text_w(space.repr(w_error)) == "<class '_socket.error'>"
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_Exception)

    # subclass of ValueError
    w_error = new_exception_class(space, 'error', space.w_ValueError)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)

    # subclass of (ValueError, TypeError)
    w_bases = space.newtuple([space.w_ValueError, space.w_TypeError])
    w_error = new_exception_class(space, 'error', w_bases)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)
    assert operr.match(space, space.w_TypeError)
Пример #2
0
def test_new_exception(space):
    w_error = new_exception_class(space, '_socket.error')
    assert w_error.getname(space) == 'error'
    assert space.str_w(space.repr(w_error)) == "<class '_socket.error'>"
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_Exception)

    # subclass of ValueError
    w_error = new_exception_class(space, 'error', space.w_ValueError)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)

    # subclass of (ValueError, TypeError)
    w_bases = space.newtuple([space.w_ValueError, space.w_TypeError])
    w_error = new_exception_class(space, 'error', w_bases)
    operr = OperationError(w_error, space.wrap("message"))
    assert operr.match(space, w_error)
    assert operr.match(space, space.w_ValueError)
    assert operr.match(space, space.w_TypeError)