#NEWLINE# def test_ftp_retries( ) : #NEWLINE# #INDENT# count = [ ] #NEWLINE# def side_effect( * args , **kwargs ) : #NEWLINE# #INDENT# if count : #NEWLINE# #INDENT# return BytesIO ( b'ftp success!' ) #NEWLINE# #UNINDENT# count . append ( 1 ) #NEWLINE# raise urllib_URLError ( 'ftp failure!' ) #NEWLINE# #UNINDENT# mock_urlopen = mock . Mock ( side_effect = count ) #NEWLINE# with mock . patch ( 'scrapelib.urllib_urlopen' , mock_urlopen ) : #NEWLINE# #INDENT# s = Scraper ( retry_attempts = 2 , retry_wait_seconds = 0.001 ) #NEWLINE# r = s . get ( 'ftp://dummy/' , retry_on_404 = True ) #NEWLINE# assert ( r . content == b'ftp success!' ) #NEWLINE# #UNINDENT# assert ( mock_urlopen . call_count == 2 ) #NEWLINE# count = [ ] #NEWLINE# mock_urlopen . reset_mock ( ) #NEWLINE# with mock . patch ( 'scrapelib.urllib_urlopen' , mock_urlopen ) : #NEWLINE# #INDENT# s = Scraper ( retry_attempts = 0 , retry_wait_seconds = 0.001 ) #NEWLINE# pytest . raises ( FTPError , s . get , 'ftp://dummy/' , retry_on_404 = True ) #NEWLINE# #UNINDENT# assert ( mock_urlopen . call_count == 1 )