#NEWLINE# def mock_subprocess( out = '' , err = '' , exit = 0 , isatty = None , insert_Popen = False ) : #NEWLINE# #INDENT# def decorator( f ) : #NEWLINE# #INDENT# @ wraps ( f ) #NEWLINE# @ patch ( 'invoke.runners.Popen' ) #NEWLINE# @ patch ( 'os.read' ) #NEWLINE# @ patch ( 'sys.stdin' , new_callable = StringIO ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# args = list ( args ) #NEWLINE# ( Popen , read , sys_stdin ) = ( args . pop ( ) , args . pop ( ) , args . pop ( ) ) #NEWLINE# process = Popen . return_value #NEWLINE# process . returncode = exit #NEWLINE# process . stdout . fileno . return_value = 1 #NEWLINE# process . stderr . fileno . return_value = 2 #NEWLINE# if ( isatty is not None ) : #NEWLINE# #INDENT# sys_stdin . isatty = Mock ( return_value = isatty ) #NEWLINE# #UNINDENT# out_file = StringIO ( out ) #NEWLINE# err_file = StringIO ( err ) #NEWLINE# def fakeread( fileno , count ) : #NEWLINE# #INDENT# fd = { #NEWLINE# #INDENT# 1 : out_file , #NEWLINE# 2 : err_file , #NEWLINE# #UNINDENT# } [ fileno ] #NEWLINE# return fd . read ( count ) #NEWLINE# #UNINDENT# read . side_effect = fakeread #NEWLINE# if insert_Popen : #NEWLINE# #INDENT# args . append ( Popen ) #NEWLINE# #UNINDENT# f ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return exit