'Assert that the expected exception is raised when calling a
function, and that the right error message is included with
that exception.
Arguments:
func -- the function to call
args -- positional arguments to `func`
kwargs -- keyword arguments to `func`
expected_exception -- exception that should be raised
expected_message -- expected exception message (or pattern
if a compiled regex object)
Returns the exception raised for further testing.'

def assertRaises(self, func, args, kwargs, expected_exception, expected_message):

    if (args is None):
        args = ()
    if (kwargs is None):
        kwargs = {}
    try:
        func(*args, **kwargs)
    except expected_exception as err:
        actual_message = str(err)
        if isinstance(expected_message, retype):
            self.assertTrue(expected_message.search(actual_message), ("expected    exception    message    pattern:\n/%s/\nactual    exception    message:\n'''%s'''\n" % (expected_message.pattern, actual_message)))
        else:
            self.assertEqual(actual_message, expected_message, ("expected    exception    message:\n'''%s'''\nactual    exception    message:\n'''%s'''\n" % (expected_message, actual_message)))
        return err
    else:
        self.fail(('expected    exception    %(expected_exception)s    not    raised\ncalled    %(func)r\nwith    args    %(args)r\nand    kwargs    %(kwargs)r\n' % locals()))
