<s> """<STR_LIT>""" <EOL> import py <EOL> from circuits import handler , Event , Component <EOL> class test ( Event ) : <EOL> """<STR_LIT>""" <EOL> success = True <EOL> failure = True <EOL> class App ( Component ) : <EOL> def __init__ ( self ) : <EOL> super ( App , self ) . __init__ ( ) <EOL> self . e = None <EOL> self . error = None <EOL> self . value = None <EOL> self . success = False <EOL> self . failure = False <EOL> @ handler ( "<STR_LIT:*>" ) <EOL> def event ( self , event , * args , ** kwargs ) : <EOL> if kwargs . get ( "<STR_LIT>" , False ) : <EOL> event . stop ( ) <EOL> def test ( self , error = False ) : <EOL> if error : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> def test_success ( self , e , value ) : <EOL> self . e = e <EOL> self . value = value <EOL> self . success = True <EOL> def test_failure ( self , e , error ) : <EOL> self . e = e <EOL> self . error = error <EOL> self . failure = True <EOL> def reraise ( e ) : <EOL> raise e <EOL> def test_success ( ) : <EOL> app = App ( ) <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> e = test ( ) <EOL> value = app . fire ( e ) <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> s = value . value <EOL> assert s == "<STR_LIT>" <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> assert app . e == e <EOL> assert app . success <EOL> assert app . e . value == value <EOL> assert app . value == value . value <EOL> def test_failure ( ) : <EOL> app = App ( ) <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> e = test ( error = True ) <EOL> x = app . fire ( e ) <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> py . test . raises ( Exception , lambda x : reraise ( x [ <NUM_LIT:1> ] ) , x . value ) <EOL> while len ( app ) : <EOL> app . flush ( ) <EOL> assert app . e == e <EOL> etype , evalue , etraceback = app . error <EOL> py . test . raises ( Exception , lambda x : reraise ( x ) , evalue ) <EOL> assert etype == Exception <EOL> assert app . failure <EOL> assert not app . success <EOL> assert app . e . value == x </s>
