def assert_warns(warning_class, func, *args, **kw):
 with WarningManager(record=True) as l:
  warnings.simplefilter('always')
  func(*args, **kw)
  if (not (len(l) > 0)):
   raise AssertionError(('No warning raised when calling %s' % func.__name__))
  if (not (l[0].category is warning_class)):
   raise AssertionError(('First warning for %s is not a %s( is %s)' % (func.__name__, warning_class, l[0])))

def assert_warns ( warning_class , func , * args , ** kw ) : with WarningManager ( record = True ) as l : warnings . simplefilter ( 'always' ) func ( * args , ** kw ) if ( not ( len ( l ) > 0 ) ) : raise AssertionError ( ( 'No warning raised when calling %s' % func . __name__ ) ) if ( not ( l [ 0 ] . category is warning_class ) ) : raise AssertionError ( ( 'First warning for %s is not a %s( is %s)' % ( func . __name__ , warning_class , l [ 0 ] ) ) )
test that a certain warning occurs .