<s> from __future__ import print_function , unicode_literals <EOL> ALL_VERBOSE = False <EOL> TEST_VERBOSE = False <EOL> CLASS_VERBOSE = False <EOL> def uses_module ( module , verbose = None ) : <EOL> """<STR_LIT>""" <EOL> def wrapped_func ( func ) : <EOL> def real_func ( self , * args , ** kargs ) : <EOL> if verbose == None : <EOL> vvv = ALL_VERBOSE or TEST_VERBOSE <EOL> else : <EOL> vvv = verbose <EOL> if vvv : <EOL> print ( "<STR_LIT>" % func . __name__ ) <EOL> resources = module . _resource_manager . get_current_resources ( ) <EOL> if vvv : <EOL> print ( "<STR_LIT>" % ( func . __name__ , resources ) ) <EOL> print ( "<STR_LIT>" % func . __name__ ) <EOL> try : <EOL> func ( self , * args , ** kargs ) <EOL> finally : <EOL> if vvv : <EOL> print ( "<STR_LIT>" % func . __name__ ) <EOL> resources_after = module . _resource_manager . get_current_resources ( ) <EOL> print ( "<STR_LIT>" % ( func . __name__ , resources_after ) ) <EOL> module . _resource_manager . remove_resources_from ( resources ) <EOL> if vvv : <EOL> print ( "<STR_LIT>" % func . __name__ ) <EOL> new_resources = module . _resource_manager . get_current_resources ( ) <EOL> print ( "<STR_LIT>" % ( func . __name__ , new_resources ) ) <EOL> real_func . __name__ = wrapped_func . __name__ <EOL> real_func . __doc___ = wrapped_func . __doc__ <EOL> return real_func <EOL> return wrapped_func <EOL> class _ResourceMonitor ( object ) : <EOL> def __init__ ( self ) : <EOL> self . before_last_setup = None <EOL> def case_uses_module ( module , verbose = None ) : <EOL> def wrapped_func ( klass ) : <EOL> if verbose == None : <EOL> vvv = ALL_VERBOSE or CLASS_VERBOSE <EOL> else : <EOL> vvv = verbose <EOL> if not hasattr ( klass , '<STR_LIT>' ) : <EOL> klass . _module_disposer = { } <EOL> klass . _module_disposer [ module . __name__ ] = _ResourceMonitor ( ) <EOL> realSetUp = klass . setUp <EOL> def wrappedSetUp ( self ) : <EOL> if vvv : <EOL> print ( "<STR_LIT>" % klass . __name__ ) <EOL> klass . _module_disposer [ module . __name__ ] . before_last_setup = module . _resource_manager . get_current_resources ( ) <EOL> if vvv : <EOL> print ( "<STR_LIT>" % ( klass . __name__ , klass . _module_disposer [ module . __name__ ] . before_last_setup ) ) <EOL> realSetUp ( self ) <EOL> klass . setUp = wrappedSetUp <EOL> realTearDown = klass . tearDown <EOL> def wrappedTearDown ( self ) : <EOL> realTearDown ( self ) <EOL> if vvv : <EOL> print ( "<STR_LIT>" % ( klass . __name__ , module . _resource_manager . get_current_resources ( ) ) ) <EOL> resources = klass . _module_disposer [ module . __name__ ] . before_last_setup <EOL> module . _resource_manager . remove_resources_from ( resources ) <EOL> if vvv : <EOL> print ( "<STR_LIT>" % ( klass . __name__ , module . _resource_manager . get_current_resources ( ) ) ) <EOL> klass . tearDown = wrappedTearDown <EOL> return klass <EOL> return wrapped_func </s>
