@@ -1472,45 +1472,49 @@ def test_remove_by_name_duplicated(self):
14721472 # suppress duplicated name warning
14731473 with warnings .catch_warnings ():
14741474 warnings .simplefilter ("ignore" )
1475-
14761475 zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1477- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1478- zh .remove ('file.txt' )
14791476
1480- # check infolist
1481- self .assertEqual (
1482- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1483- [ComparableZipInfo (zi ) for zi in [zinfos [0 ], zinfos [2 ]]],
1484- )
1477+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1478+ zh .remove ('file.txt' )
14851479
1486- # check NameToInfo cache
1487- self .assertEqual (
1488- ComparableZipInfo ( zh .getinfo ( 'file.txt' )) ,
1489- ComparableZipInfo ( zinfos [0 ]) ,
1490- )
1480+ # check infolist
1481+ self .assertEqual (
1482+ [ ComparableZipInfo ( zi ) for zi in zh .infolist ()] ,
1483+ [ ComparableZipInfo ( zi ) for zi in [ zinfos [0 ], zinfos [ 2 ]]] ,
1484+ )
14911485
1492- # make sure the zip file is still valid
1493- with zipfile .ZipFile (TESTFN ) as zh :
1494- self .assertIsNone (zh .testzip ())
1486+ # check NameToInfo cache
1487+ self .assertEqual (
1488+ ComparableZipInfo (zh .getinfo ('file.txt' )),
1489+ ComparableZipInfo (zinfos [0 ]),
1490+ )
14951491
1492+ # make sure the zip file is still valid
1493+ with zipfile .ZipFile (TESTFN ) as zh :
1494+ self .assertIsNone (zh .testzip ())
1495+
1496+ # suppress duplicated name warning
1497+ with warnings .catch_warnings ():
1498+ warnings .simplefilter ("ignore" )
14961499 zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1497- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1498- zh .remove ('file.txt' )
1499- zh .remove ('file.txt' )
15001500
1501- # check infolist
1502- self .assertEqual (
1503- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1504- [ComparableZipInfo (zi ) for zi in [zinfos [2 ]]],
1505- )
1501+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1502+ zh .remove ('file.txt' )
1503+ zh .remove ('file.txt' )
15061504
1507- # check NameToInfo cache
1508- with self .assertRaises (KeyError ):
1509- zh .getinfo ('file.txt' )
1505+ # check infolist
1506+ self .assertEqual (
1507+ [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1508+ [ComparableZipInfo (zi ) for zi in [zinfos [2 ]]],
1509+ )
15101510
1511- # make sure the zip file is still valid
1512- with zipfile .ZipFile (TESTFN ) as zh :
1513- self .assertIsNone (zh .testzip ())
1511+ # check NameToInfo cache
1512+ with self .assertRaises (KeyError ):
1513+ zh .getinfo ('file.txt' )
1514+
1515+ # make sure the zip file is still valid
1516+ with zipfile .ZipFile (TESTFN ) as zh :
1517+ self .assertIsNone (zh .testzip ())
15141518
15151519 def test_remove_by_zinfo_duplicated (self ):
15161520 test_files = [
@@ -1522,66 +1526,74 @@ def test_remove_by_zinfo_duplicated(self):
15221526 # suppress duplicated name warning
15231527 with warnings .catch_warnings ():
15241528 warnings .simplefilter ("ignore" )
1525-
15261529 zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1527- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1528- zh .remove (zh .infolist ()[0 ])
15291530
1530- # check infolist
1531- self .assertEqual (
1532- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1533- [ComparableZipInfo (zi ) for zi in [zinfos [1 ], zinfos [2 ]]],
1534- )
1531+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1532+ zh .remove (zh .infolist ()[0 ])
15351533
1536- # check NameToInfo cache
1537- self .assertEqual (
1538- ComparableZipInfo ( zh .getinfo ( 'file.txt' )) ,
1539- ComparableZipInfo ( zinfos [1 ]) ,
1540- )
1534+ # check infolist
1535+ self .assertEqual (
1536+ [ ComparableZipInfo ( zi ) for zi in zh .infolist ()] ,
1537+ [ ComparableZipInfo ( zi ) for zi in [ zinfos [1 ], zinfos [ 2 ]]] ,
1538+ )
15411539
1542- # make sure the zip file is still valid
1543- with zipfile .ZipFile (TESTFN ) as zh :
1544- self .assertIsNone (zh .testzip ())
1540+ # check NameToInfo cache
1541+ self .assertEqual (
1542+ ComparableZipInfo (zh .getinfo ('file.txt' )),
1543+ ComparableZipInfo (zinfos [1 ]),
1544+ )
15451545
1546+ # make sure the zip file is still valid
1547+ with zipfile .ZipFile (TESTFN ) as zh :
1548+ self .assertIsNone (zh .testzip ())
1549+
1550+ # suppress duplicated name warning
1551+ with warnings .catch_warnings ():
1552+ warnings .simplefilter ("ignore" )
15461553 zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1547- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1548- zh .remove (zh .infolist ()[1 ])
15491554
1550- # check infolist
1551- self .assertEqual (
1552- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1553- [ComparableZipInfo (zi ) for zi in [zinfos [0 ], zinfos [2 ]]],
1554- )
1555+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1556+ zh .remove (zh .infolist ()[1 ])
1557+
1558+ # check infolist
1559+ self .assertEqual (
1560+ [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1561+ [ComparableZipInfo (zi ) for zi in [zinfos [0 ], zinfos [2 ]]],
1562+ )
15551563
1556- # check NameToInfo cache
1557- self .assertEqual (
1558- ComparableZipInfo (zh .getinfo ('file.txt' )),
1559- ComparableZipInfo (zinfos [0 ]),
1560- )
1564+ # check NameToInfo cache
1565+ self .assertEqual (
1566+ ComparableZipInfo (zh .getinfo ('file.txt' )),
1567+ ComparableZipInfo (zinfos [0 ]),
1568+ )
15611569
1562- # make sure the zip file is still valid
1563- with zipfile .ZipFile (TESTFN ) as zh :
1564- self .assertIsNone (zh .testzip ())
1570+ # make sure the zip file is still valid
1571+ with zipfile .ZipFile (TESTFN ) as zh :
1572+ self .assertIsNone (zh .testzip ())
15651573
1574+ # suppress duplicated name warning
1575+ with warnings .catch_warnings ():
1576+ warnings .simplefilter ("ignore" )
15661577 zinfos = self ._prepare_zip_from_test_files (TESTFN , test_files )
1567- with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1568- infolist = zh .infolist ().copy ()
1569- zh .remove (infolist [0 ])
1570- zh .remove (infolist [1 ])
1571-
1572- # check infolist
1573- self .assertEqual (
1574- [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1575- [ComparableZipInfo (zi ) for zi in [zinfos [2 ]]],
1576- )
1577-
1578- # check NameToInfo cache
1579- with self .assertRaises (KeyError ):
1580- zh .getinfo ('file.txt' )
1581-
1582- # make sure the zip file is still valid
1583- with zipfile .ZipFile (TESTFN ) as zh :
1584- self .assertIsNone (zh .testzip ())
1578+
1579+ with zipfile .ZipFile (TESTFN , 'a' , self .compression ) as zh :
1580+ infolist = zh .infolist ().copy ()
1581+ zh .remove (infolist [0 ])
1582+ zh .remove (infolist [1 ])
1583+
1584+ # check infolist
1585+ self .assertEqual (
1586+ [ComparableZipInfo (zi ) for zi in zh .infolist ()],
1587+ [ComparableZipInfo (zi ) for zi in [zinfos [2 ]]],
1588+ )
1589+
1590+ # check NameToInfo cache
1591+ with self .assertRaises (KeyError ):
1592+ zh .getinfo ('file.txt' )
1593+
1594+ # make sure the zip file is still valid
1595+ with zipfile .ZipFile (TESTFN ) as zh :
1596+ self .assertIsNone (zh .testzip ())
15851597
15861598 def test_remove_zip64 (self ):
15871599 for i in range (0 , 3 ):
0 commit comments