@@ -4312,9 +4312,9 @@ def test_write_to_filename_with_encoding(self):
43124312
43134313 tree .write (TESTFN , encoding = 'ISO-8859-1' )
43144314 with open (TESTFN , 'rb' ) as f :
4315- self .assertEqual (f .read (), convlinesep (
4315+ self .assertEqual (f .read (),
43164316 b'''<?xml version='1.0' encoding='ISO-8859-1'?>\n '''
4317- b'''<site>\xf8 </site>''' ))
4317+ b'''<site>\xf8 </site>''' )
43184318
43194319 def test_write_to_filename_as_unicode (self ):
43204320 self .addCleanup (os_helper .unlink , TESTFN )
@@ -4357,6 +4357,25 @@ def test_write_to_binary_file(self):
43574357 with open (TESTFN , 'rb' ) as f :
43584358 self .assertEqual (f .read (), b'''<site>ø</site>''' )
43594359
4360+ def test_write_with_and_without_context_manager_same_output (self ):
4361+ self .addCleanup (os_helper .unlink , TESTFN )
4362+ testfn2 = TESTFN + '2'
4363+ self .addCleanup (os_helper .unlink , testfn2 )
4364+
4365+ tree = ET .ElementTree (ET .XML ('''<site>\x0a </site>''' ))
4366+ tree .write (TESTFN , encoding = 'utf-8' )
4367+ with open (TESTFN , 'rb' ) as f :
4368+ output_without_context_manager = f .read ()
4369+
4370+ with open (testfn2 , 'wb' ) as f :
4371+ tree .write (f , encoding = 'utf-8' )
4372+ self .assertFalse (f .closed )
4373+ with open (testfn2 , 'rb' ) as f :
4374+ output_with_context_manager = f .read ()
4375+
4376+ self .assertEqual (output_without_context_manager ,
4377+ output_with_context_manager )
4378+
43604379 def test_write_to_binary_file_with_encoding (self ):
43614380 self .addCleanup (os_helper .unlink , TESTFN )
43624381 tree = ET .ElementTree (ET .XML ('''<site>\xf8 </site>''' ))
0 commit comments