@@ -207,9 +207,8 @@ def test_create_and_list_files_in_sub_directory(self):
207207
208208 def test_read_file_with_content (self ):
209209 file_name = 'readme.txt'
210- file_content = 'this is a test file {0}' .format (randint (5000 , 5500 ))
211- self .docker .run ('echo \" {0}\" > ~/{1}; cat readme.txt' .format (file_content , file_name ))
212-
210+ file_content = 'this is a test file {0}\n ' .format (randint (5000 , 5500 ))
211+ self .docker .write_file (file_name , file_content )
213212 self .assertEqual (self .docker .read_file (file_name ), file_content )
214213
215214 def test_read_file_that_dont_exist (self ):
@@ -221,6 +220,17 @@ def test_read_file_that_dont_exist(self):
221220 path
222221 )
223222
223+ def test_read_file_eof_newline (self ):
224+ path = '/etc/hostname'
225+ content = self .docker .read_file (path )
226+ self .assertTrue (content .endswith ('\n ' ))
227+
228+ def test_write_file_read_file (self ):
229+ path = 'testfile'
230+ content = 'this is a nice file\n '
231+ self .docker .write_file (path , content )
232+ self .assertEqual (content , self .docker .read_file (path ))
233+
224234 def test_directory_exist (self ):
225235 self .assertTrue (self .docker .directory_exist ('~/' ))
226236 self .assertFalse (self .docker .directory_exist ('does-not-exist' ))
@@ -234,15 +244,16 @@ def test_combine_output(self):
234244 self .docker .combine_outputs = True
235245 result = self .docker .run ('ls does-not-exist' )
236246 self .assertEqual (result .err , '' )
237- self .assertEqual (result .out , 'ls: cannot access does-not-exist: No such file or directory' )
247+ self .assertEqual (result .out ,
248+ 'ls: cannot access does-not-exist: No such file or directory\n ' )
238249
239250 def test_privilege (self ):
240251 Docker (privilege = True ).start ()
241252
242253 def test_write_file_append (self ):
243254 path = 'readme.txt'
244- old_content = 'hi'
245- content = 'this is a readme'
255+ old_content = 'hi\n '
256+ content = 'this is a readme\n '
246257 self .docker .run ('echo "{0}" > {1}' .format (old_content , path ))
247258
248259 self .docker .write_file (path , content , append = True )
@@ -252,7 +263,7 @@ def test_write_file_append(self):
252263 def test_write_file_no_append (self ):
253264 path = 'readme.txt'
254265 old_content = 'hi'
255- content = 'this is a readme'
266+ content = 'this is a readme\n '
256267 self .docker .run ('echo "{0}" > {1}' .format (old_content , path ))
257268
258269 self .docker .write_file (path , content , append = False )
@@ -261,7 +272,7 @@ def test_write_file_no_append(self):
261272
262273 def test_write_file_quotes (self ):
263274 path = 'readme.txt'
264- content = 'this is a "readme"'
275+ content = 'this is a "readme"\n '
265276
266277 self .docker .write_file (path , content , append = False )
267278 written_content = self .docker .read_file (path )
0 commit comments