'Fail if the given function doesn\'t generate the specified warning when
called. It calls the function, checks the warning, and forwards the
result of the function if everything is fine.
@param category: the category of the warning to check.
@param message: the output message of the warning to check.
@param filename: the filename where the warning should come from.
@param f: the function which is supposed to generate the warning.
@type f: any callable.
@param args: the arguments to C{f}.
@param kwargs: the keywords arguments to C{f}.
@return: the result of the original function C{f}.'

def assertWarns(self, category, message, filename, f, *args, **kwargs):

    warningsShown = []
    result = _collectWarnings(warningsShown.append, f, *args, **kwargs)
    if (not warningsShown):
        self.fail('No    warnings    emitted')
    first = warningsShown[0]
    for other in warningsShown[1:]:
        if ((other.message, other.category) != (first.message, first.category)):
            self.fail("Can't    handle    different    warnings")
    self.assertEqual(first.message, message)
    self.assertIdentical(first.category, category)
    self.assertTrue(filename.startswith(first.filename), ('Warning    in    %r,    expected    %r' % (first.filename, filename)))
    return result
