@@ -1290,6 +1290,23 @@ def test_verify(self):
12901290 zh .remove (file )
12911291 mock_fn .assert_not_called ()
12921292
1293+ # mode 'w': error and do nothing
1294+ with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
1295+ zh .writestr (file , data )
1296+ with mock .patch ('zipfile.ZipFile._remove_members' ) as mock_fn :
1297+ with self .assertRaises (ValueError ):
1298+ zh .remove (file )
1299+ mock_fn .assert_not_called ()
1300+
1301+ # mode 'x': error and do nothing
1302+ os .remove (TESTFN )
1303+ with zipfile .ZipFile (TESTFN , 'x' , self .compression ) as zh :
1304+ zh .writestr (file , data )
1305+ with mock .patch ('zipfile.ZipFile._remove_members' ) as mock_fn :
1306+ with self .assertRaises (ValueError ):
1307+ zh .remove (file )
1308+ mock_fn .assert_not_called ()
1309+
12931310 # mode 'a': the most general use case
12941311 with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
12951312 zh .writestr (file , data )
@@ -1318,21 +1335,6 @@ def test_verify(self):
13181335 zh .remove (zinfo )
13191336 mock_fn .assert_not_called ()
13201337
1321- # mode 'w': like 'a'; allows removing a just written member
1322- with zipfile .ZipFile (TESTFN , 'w' , self .compression ) as zh :
1323- zh .writestr (file , data )
1324- with mock .patch ('zipfile.ZipFile._remove_members' ) as mock_fn :
1325- zh .remove (file )
1326- mock_fn .assert_called_once_with ({zh .getinfo (file )})
1327-
1328- # mode 'x': like 'w'
1329- os .remove (TESTFN )
1330- with zipfile .ZipFile (TESTFN , 'x' , self .compression ) as zh :
1331- zh .writestr (file , data )
1332- with mock .patch ('zipfile.ZipFile._remove_members' ) as mock_fn :
1333- zh .remove (file )
1334- mock_fn .assert_called_once_with ({zh .getinfo (file )})
1335-
13361338 def test_zip64 (self ):
13371339 """Test if members use zip64."""
13381340 file = 'datafile.txt'
0 commit comments