@@ -734,6 +734,48 @@ class LzmaTestZip64InSmallFiles(AbstractTestZip64InSmallFiles,
734734 compression = zipfile .ZIP_LZMA
735735
736736
737+ class AbstractWriterTests :
738+
739+ def tearDown (self ):
740+ unlink (TESTFN2 )
741+
742+ def test_close_after_close (self ):
743+ data = b'content'
744+ with zipfile .ZipFile (TESTFN2 , "w" , self .compression ) as zipf :
745+ w = zipf .open ('test' , 'w' )
746+ w .write (data )
747+ w .close ()
748+ self .assertTrue (w .closed )
749+ w .close ()
750+ self .assertTrue (w .closed )
751+ self .assertEqual (zipf .read ('test' ), data )
752+
753+ def test_write_after_close (self ):
754+ data = b'content'
755+ with zipfile .ZipFile (TESTFN2 , "w" , self .compression ) as zipf :
756+ w = zipf .open ('test' , 'w' )
757+ w .write (data )
758+ w .close ()
759+ self .assertTrue (w .closed )
760+ self .assertRaises (ValueError , w .write , b'' )
761+ self .assertEqual (zipf .read ('test' ), data )
762+
763+ class StoredWriterTests (AbstractWriterTests , unittest .TestCase ):
764+ compression = zipfile .ZIP_STORED
765+
766+ @requires_zlib
767+ class DeflateWriterTests (AbstractWriterTests , unittest .TestCase ):
768+ compression = zipfile .ZIP_DEFLATED
769+
770+ @requires_bz2
771+ class Bzip2WriterTests (AbstractWriterTests , unittest .TestCase ):
772+ compression = zipfile .ZIP_BZIP2
773+
774+ @requires_lzma
775+ class LzmaWriterTests (AbstractWriterTests , unittest .TestCase ):
776+ compression = zipfile .ZIP_LZMA
777+
778+
737779class PyZipFileTests (unittest .TestCase ):
738780 def assertCompiledIn (self , name , namelist ):
739781 if name + 'o' not in namelist :
0 commit comments