#NEWLINE# def test_write_file( self ) : #NEWLINE# #INDENT# mode_map = [ ( ( 'w' , 'r' ) , 'my test\ndata\n\n' , False ) , ( ( 'wb' , 'rb' ) , '\r\n' . join ( ( chr ( x ) for x in ( 32 , 125 , 0 ) ) ) . encode ( ) , False ) , ( ( 'wb' , 'rb' ) , 'my test\ndata\n\n' , True ) ] #NEWLINE# with testutils . create_tempdir ( ) as temp : #NEWLINE# #INDENT# ( fd , path ) = tempfile . mkstemp ( dir = temp ) #NEWLINE# os . close ( fd ) #NEWLINE# for ( ( write , read ) , data , encode ) in mode_map : #NEWLINE# #INDENT# encoding . write_file ( path , data , mode = write ) #NEWLINE# with open ( path , read ) as stream : #NEWLINE# #INDENT# content = stream . read ( ) #NEWLINE# #UNINDENT# if read : #NEWLINE# #INDENT# data = data . encode ( ) #NEWLINE# #UNINDENT# self . assertEqual ( data , content )