#NEWLINE# def test_urlretrieve( ) : #NEWLINE# #INDENT# s = Scraper ( requests_per_minute = 0 ) #NEWLINE# with mock . patch . object ( requests . Session , 'request' , mock_200 ) : #NEWLINE# #INDENT# ( fname , resp ) = s . urlretrieve ( 'http://dummy/' ) #NEWLINE# with open ( fname ) as f : #NEWLINE# #INDENT# assert ( f . read ( ) == 'ok' ) #NEWLINE# assert ( resp . code == 200 ) #NEWLINE# #UNINDENT# os . remove ( fname ) #NEWLINE# ( fh , set_fname ) = tempfile . mkstemp ( ) #NEWLINE# ( fname , resp ) = s . urlretrieve ( 'http://dummy/' , set_fname ) #NEWLINE# assert ( fname == set_fname ) #NEWLINE# with open ( set_fname ) as f : #NEWLINE# #INDENT# assert ( f . read ( ) == 'ok' ) #NEWLINE# assert ( resp . code == 200 ) #NEWLINE# #UNINDENT# os . remove ( set_fname ) #NEWLINE# dirname = os . path . dirname ( set_fname ) #NEWLINE# ( fname , resp ) = s . urlretrieve ( 'http://dummy/' , dir = dirname ) #NEWLINE# assert ( os . path . dirname ( fname ) == dirname ) #NEWLINE# with open ( fname ) as f : #NEWLINE# #INDENT# assert ( f . read ( ) == 'ok' ) #NEWLINE# assert ( resp . code == 200 ) #NEWLINE# #UNINDENT# os . remove ( fname )