#NEWLINE# @ trap #NEWLINE# def expect( invocation , out = None , err = None , program = None , invoke = True , test = None ) : #NEWLINE# #INDENT# '\n    Run ``invocation`` via ``program`` and expect resulting output to match.\n\n    May give one or both of ``out``/``err`` (but not neither).\n\n    ``program`` defaults to ``Program()``.\n\n    To skip automatically assuming the argv under test starts with ``"invoke\n    "``, say ``invoke=False``.\n\n    To customize the operator used for testing (default: equality), use\n    ``test`` (which should be an assertion wrapper of some kind).\n    ' #NEWLINE# if ( program is None ) : #NEWLINE# #INDENT# program = Program ( ) #NEWLINE# #UNINDENT# if invoke : #NEWLINE# #INDENT# invocation = 'invoke {0}' . format ( invocation ) #NEWLINE# #UNINDENT# program . run ( invocation , exit = False ) #NEWLINE# if ( out is not None ) : #NEWLINE# #INDENT# ( test or eq_ ) ( sys . stdout . getvalue ( ) , test ) #NEWLINE# #UNINDENT# if ( err is not None ) : #NEWLINE# #INDENT# ( test or eq_ ) ( sys . stderr . getvalue ( ) , err )