#NEWLINE# def test_functionCalledByState( self ) : #NEWLINE# #INDENT# '\n        A method defined with L{makeStatefulDispatcher} invokes a second\n        method based on the current state of the object.\n        ' #NEWLINE# class Foo ( ) : #NEWLINE# #INDENT# _state = 'A' #NEWLINE# def bar( self ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# bar = makeStatefulDispatcher ( 'quux' , bar ) #NEWLINE# def _quux_A( self ) : #NEWLINE# #INDENT# return 'a' #NEWLINE# #UNINDENT# def _quux_B( self ) : #NEWLINE# #INDENT# return 'b' #NEWLINE# #UNINDENT# #UNINDENT# stateful = Foo ( ) #NEWLINE# self . assertEqual ( stateful . bar ( ) , 'a' ) #NEWLINE# stateful . _state = 'B' #NEWLINE# self . assertEqual ( stateful . bar ( ) , 'b' ) #NEWLINE# stateful . _state = 'C' #NEWLINE# self . assertRaises ( RuntimeError , stateful . bar )