def failUnlessWarns(self, category, message, filename, f,<EOL>*args, **kwargs):
warningsShown = []<EOL>def warnExplicit(*args):<EOL><INDENT>warningsShown.append(args)<EOL><DEDENT>origExplicit = warnings.warn_explicit<EOL>try:<EOL><INDENT>warnings.warn_explicit = warnExplicit<EOL>result = f(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>warnings.warn_explicit = origExplicit<EOL><DEDENT>if not warningsShown:<EOL><INDENT>self.fail("<STR_LIT>")<EOL><DEDENT>first = warningsShown[<NUM_LIT:0>]<EOL>for other in warningsShown[<NUM_LIT:1>:]:<EOL><INDENT>if other[:<NUM_LIT:2>] != first[:<NUM_LIT:2>]:<EOL><INDENT>self.fail("<STR_LIT>")<EOL><DEDENT><DEDENT>gotMessage, gotCategory, gotFilename, lineno = first[:<NUM_LIT:4>]<EOL>self.assertEqual(gotMessage, message)<EOL>self.assertIdentical(gotCategory, category)<EOL>self.failUnless(<EOL>filename.startswith(gotFilename),<EOL>'<STR_LIT>' % (gotFilename, filename))<EOL>return result<EOL>
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}.