def deprecated_call(func=None, *args, **kwargs):
 if (not func):
  return WarningsChecker(expected_warning=DeprecationWarning)
 categories = []
 def warn_explicit(message, category, *args, **kwargs):
  categories.append(category)
  old_warn_explicit(message, category, *args, **kwargs)
 def warn(message, category=None, *args, **kwargs):
  if isinstance(message, Warning):
   categories.append(message.__class__)
  else:
   categories.append(category)
  old_warn(message, category, *args, **kwargs)
 old_warn = warnings.warn
 old_warn_explicit = warnings.warn_explicit
 warnings.warn_explicit = warn_explicit
 warnings.warn = warn
 try:
  ret = func(*args, **kwargs)
 finally:
  warnings.warn_explicit = old_warn_explicit
  warnings.warn = old_warn
 deprecation_categories = (DeprecationWarning, PendingDeprecationWarning)
 if (not any((issubclass(c, deprecation_categories) for c in categories))):
  __tracebackhide__ = True
  raise AssertionError(('%r did not produce DeprecationWarning' % (func,)))
 return ret

def deprecated_call ( func = None , * args , ** kwargs ) : if ( not func ) : return WarningsChecker ( expected_warning = DeprecationWarning ) categories = [ ] def warn_explicit ( message , category , * args , ** kwargs ) : categories . append ( category ) old_warn_explicit ( message , category , * args , ** kwargs ) def warn ( message , category = None , * args , ** kwargs ) : if isinstance ( message , Warning ) : categories . append ( message . __class__ ) else : categories . append ( category ) old_warn ( message , category , * args , ** kwargs ) old_warn = warnings . warn old_warn_explicit = warnings . warn_explicit warnings . warn_explicit = warn_explicit warnings . warn = warn try : ret = func ( * args , ** kwargs ) finally : warnings . warn_explicit = old_warn_explicit warnings . warn = old_warn deprecation_categories = ( DeprecationWarning , PendingDeprecationWarning ) if ( not any ( ( issubclass ( c , deprecation_categories ) for c in categories ) ) ) : __tracebackhide__ = True raise AssertionError ( ( '%r did not produce DeprecationWarning' % ( func , ) ) ) return ret
assert that calling func triggers a deprecationwarning or pendingdeprecationwarning .