#NEWLINE# def test_bad_hostkey( instance , paramiko ) : #NEWLINE# #INDENT# with open ( instance . master . known_hosts , 'w' ) as f : #NEWLINE# #INDENT# f . write ( 'foo' ) #NEWLINE# #UNINDENT# instance . config [ 'host' ] = 'localhost' #NEWLINE# instance . config [ 'fingerprint' ] = 'foo' #NEWLINE# with patch ( ( '%s.SSHClient.connect' % paramiko . __name__ ) ) as connect_mock : #NEWLINE# #INDENT# connect_mock . side_effect = [ paramiko . BadHostKeyException ( 'localhost' , paramiko . PKey ( 'bar' ) , paramiko . PKey ( 'foo' ) ) , None ] #NEWLINE# instance . init_ssh_key ( ) #NEWLINE# #UNINDENT# assert os . path . exists ( instance . master . known_hosts ) #NEWLINE# with open ( paramiko . master . known_hosts ) as f : #NEWLINE# #INDENT# assert ( f . read ( ) == '' )