@@ -69,8 +69,9 @@ def test_quotation_mark_handling(self, mock_run):
6969 docker = Docker ()
7070 docker .run ('echo "hi there"' )
7171 docker .run ("echo 'hi there'" )
72- expected = ('docker exec -i {} bash -c \' cd ~/ && echo "hi there" ; '
73- 'echo "--return-$?--"\' ' .format (docker .container_name ), '' )
72+ expected = (
73+ 'docker exec -i {} bash -c \' cd ~/ && echo "hi there"\' ' .format (docker .container_name ),
74+ '' )
7475
7576 mock_run .assert_has_calls ([mock .call (* expected ), mock .call (* expected )])
7677
@@ -79,9 +80,9 @@ def test_quotation_mark_handling(self, mock_run):
7980 def test_env_variables (self , mock_run ):
8081 docker = Docker (env_variables = {'CI' : 1 , 'FRIGG' : 1 })
8182 docker .run ('ls' )
82- mock_run .assert_called_once_with ('docker exec -i {} bash -c \' cd ~/ && CI=1 FRIGG=1 ls ;'
83- ' echo "--return-$?--" \' ' .format (docker .container_name ),
84- '' )
83+ mock_run .assert_called_once_with (
84+ 'docker exec -i {} bash -c \' cd ~/ && CI=1 FRIGG=1 ls \' ' .format (docker .container_name ),
85+ '' )
8586
8687 @mock .patch ('docker.manager.execute' )
8788 def test_single_port_mappping (self , mock_run ):
@@ -206,9 +207,8 @@ def test_create_and_list_files_in_sub_directory(self):
206207
207208 def test_read_file_with_content (self ):
208209 file_name = 'readme.txt'
209- file_content = 'this is a test file {0}' .format (randint (5000 , 5500 ))
210- self .docker .run ('echo \" {0}\" > ~/{1}; cat readme.txt' .format (file_content , file_name ))
211-
210+ file_content = 'this is a test file {0}\n ' .format (randint (5000 , 5500 ))
211+ self .docker .write_file (file_name , file_content )
212212 self .assertEqual (self .docker .read_file (file_name ), file_content )
213213
214214 def test_read_file_that_dont_exist (self ):
@@ -220,6 +220,17 @@ def test_read_file_that_dont_exist(self):
220220 path
221221 )
222222
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+
223234 def test_directory_exist (self ):
224235 self .assertTrue (self .docker .directory_exist ('~/' ))
225236 self .assertFalse (self .docker .directory_exist ('does-not-exist' ))
@@ -233,15 +244,16 @@ def test_combine_output(self):
233244 self .docker .combine_outputs = True
234245 result = self .docker .run ('ls does-not-exist' )
235246 self .assertEqual (result .err , '' )
236- 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 ' )
237249
238250 def test_privilege (self ):
239251 Docker (privilege = True ).start ()
240252
241253 def test_write_file_append (self ):
242254 path = 'readme.txt'
243- old_content = 'hi'
244- content = 'this is a readme'
255+ old_content = 'hi\n '
256+ content = 'this is a readme\n '
245257 self .docker .run ('echo "{0}" > {1}' .format (old_content , path ))
246258
247259 self .docker .write_file (path , content , append = True )
@@ -251,7 +263,7 @@ def test_write_file_append(self):
251263 def test_write_file_no_append (self ):
252264 path = 'readme.txt'
253265 old_content = 'hi'
254- content = 'this is a readme'
266+ content = 'this is a readme\n '
255267 self .docker .run ('echo "{0}" > {1}' .format (old_content , path ))
256268
257269 self .docker .write_file (path , content , append = False )
@@ -260,8 +272,16 @@ def test_write_file_no_append(self):
260272
261273 def test_write_file_quotes (self ):
262274 path = 'readme.txt'
263- content = 'this is a "readme"'
275+ content = 'this is a "readme"\n '
264276
265277 self .docker .write_file (path , content , append = False )
266278 written_content = self .docker .read_file (path )
267279 self .assertEqual (written_content , content )
280+
281+ def test_run_return_code (self ):
282+ code = 4
283+ path = 'testfile'
284+ content = 'exit {0}\n ' .format (code )
285+ self .docker .write_file (path , content )
286+ result = self .docker .run ('bash {0}' .format (path ))
287+ self .assertEqual (code , result .return_code )
0 commit comments