Skip to content

Commit 1ece5b1

Browse files
committed
Refactor and optimize RepackHelperMixin
1 parent c759b63 commit 1ece5b1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,9 +1379,18 @@ def struct_pack_no_dd_sig(fmt, *values):
13791379

13801380
class RepackHelperMixin:
13811381
"""Common helpers for remove and repack."""
1382-
def _prepare_zip_from_test_files(self, zfname, test_files, force_zip64=False):
1382+
@classmethod
1383+
def _prepare_test_files(cls):
1384+
return [
1385+
('file0.txt', b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'),
1386+
('file1.txt', b'Duis aute irure dolor in reprehenderit in voluptate velit esse'),
1387+
('file2.txt', b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'),
1388+
]
1389+
1390+
@classmethod
1391+
def _prepare_zip_from_test_files(cls, zfname, test_files, force_zip64=False):
13831392
zinfos = []
1384-
with zipfile.ZipFile(zfname, 'w', self.compression) as zh:
1393+
with zipfile.ZipFile(zfname, 'w', cls.compression) as zh:
13851394
for file, data in test_files:
13861395
with zh.open(file, 'w', force_zip64=force_zip64) as fh:
13871396
fh.write(data)
@@ -1392,11 +1401,7 @@ def _prepare_zip_from_test_files(self, zfname, test_files, force_zip64=False):
13921401
class AbstractRemoveTests(RepackHelperMixin):
13931402
@classmethod
13941403
def setUpClass(cls):
1395-
cls.test_files = [
1396-
('file0.txt', b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'),
1397-
('file1.txt', b'Duis aute irure dolor in reprehenderit in voluptate velit esse'),
1398-
('file2.txt', b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'),
1399-
]
1404+
cls.test_files = cls._prepare_test_files()
14001405

14011406
def tearDown(self):
14021407
unlink(TESTFN)
@@ -1683,11 +1688,7 @@ class ZstdRemoveTests(AbstractRemoveTests, unittest.TestCase):
16831688
class AbstractRepackTests(RepackHelperMixin):
16841689
@classmethod
16851690
def setUpClass(cls):
1686-
cls.test_files = [
1687-
('file0.txt', b'Lorem ipsum dolor sit amet, consectetur adipiscing elit'),
1688-
('file1.txt', b'Duis aute irure dolor in reprehenderit in voluptate velit esse'),
1689-
('file2.txt', b'Sed ut perspiciatis unde omnis iste natus error sit voluptatem'),
1690-
]
1691+
cls.test_files = cls._prepare_test_files()
16911692

16921693
def tearDown(self):
16931694
unlink(TESTFN)

0 commit comments

Comments
 (0)