2
2
# SPDX-License-Identifier: GPL-3.0-or-later
3
3
4
4
""" CVE Binary Tool tests for the extractor function """
5
+ from __future__ import annotations
6
+
5
7
import shutil
6
8
import sys
7
9
import tarfile
21
23
ZST_FILE_PATH ,
22
24
download_file ,
23
25
)
24
- from typing import Dict , List
25
26
from zipfile import ZipFile , ZipInfo
26
27
27
28
import pytest
@@ -63,12 +64,12 @@ async def extract_files(self, filenames):
63
64
yield await ectx .aio_extract (str (self .tempdir / filename ))
64
65
65
66
@pytest .fixture
66
- def extension_list (self ) -> List [str ]:
67
+ def extension_list (self ) -> list [str ]:
67
68
return []
68
69
69
70
@pytest .mark .asyncio
70
71
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
71
- async def test_bad_files (self , extension_list : List [str ]):
72
+ async def test_bad_files (self , extension_list : list [str ]):
72
73
"""Test handling of invalid files. No exceptions should be raised."""
73
74
for extension in extension_list :
74
75
filename = self .tempdir / f"empty-file{ extension } "
@@ -99,11 +100,11 @@ def setup_method(self):
99
100
tar .close ()
100
101
101
102
@pytest .fixture
102
- def extension_list (self ) -> List [str ]:
103
+ def extension_list (self ) -> list [str ]:
103
104
return self .extractor .file_extractors [self .extractor .extract_file_tar ]
104
105
105
106
@pytest .mark .asyncio
106
- async def test_extract_file_tar (self , extension_list : List [str ]):
107
+ async def test_extract_file_tar (self , extension_list : list [str ]):
107
108
"""Test the tar file extraction"""
108
109
async for dir_path in self .extract_files (
109
110
[f"test{ extension } " for extension in extension_list ]
@@ -129,12 +130,12 @@ def setup_class(cls):
129
130
download_file (CURL_7_20_0_URL , cls .tempdir / "test.rpm" )
130
131
131
132
@pytest .fixture
132
- def extension_list (self ) -> List [str ]:
133
+ def extension_list (self ) -> list [str ]:
133
134
return self .extractor .file_extractors [self .extractor .extract_file_rpm ]
134
135
135
136
@pytest .mark .asyncio
136
137
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
137
- async def test_extract_file_rpm (self , extension_list : List [str ]):
138
+ async def test_extract_file_rpm (self , extension_list : list [str ]):
138
139
"""Test the rpm file extraction"""
139
140
async for extracted_path in self .extract_files (
140
141
[f"test{ extension } " for extension in extension_list ]
@@ -143,7 +144,7 @@ async def test_extract_file_rpm(self, extension_list: List[str]):
143
144
144
145
@pytest .mark .asyncio
145
146
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
146
- async def test_extract_file_rpm_no_rpm2cipo (self , extension_list : List [str ]):
147
+ async def test_extract_file_rpm_no_rpm2cipo (self , extension_list : list [str ]):
147
148
"""Test rpm extraction using rpmfile"""
148
149
with unittest .mock .patch (
149
150
"cve_bin_tool.async_utils.aio_inpath" ,
@@ -162,15 +163,15 @@ def setup_method(self):
162
163
shutil .copyfile (ZST_FILE_PATH , self .tempdir / "test.zst" )
163
164
164
165
@pytest .fixture
165
- def extension_list (self ) -> List [str ]:
166
+ def extension_list (self ) -> list [str ]:
166
167
return self .extractor .file_extractors [self .extractor .extract_file_zst ]
167
168
168
169
@pytest .mark .asyncio
169
170
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
170
171
@pytest .mark .skipif (
171
172
sys .platform == "win32" , reason = "windows zst support incomplete"
172
173
)
173
- async def test_extract_file_zst (self , extension_list : List [str ]):
174
+ async def test_extract_file_zst (self , extension_list : list [str ]):
174
175
"""Test the zst file extraction"""
175
176
async for extracted_path in self .extract_files (
176
177
[f"test{ extension } " for extension in extension_list ]
@@ -188,7 +189,7 @@ def setup_method(self):
188
189
shutil .copyfile (PKG_FILE_PATH , self .tempdir / "test.pkg" )
189
190
190
191
@pytest .fixture
191
- def extension_list (self ) -> List [str ]:
192
+ def extension_list (self ) -> list [str ]:
192
193
return self .extractor .file_extractors [self .extractor .extract_file_pkg ]
193
194
194
195
@pytest .mark .parametrize (
@@ -202,8 +203,8 @@ def extension_list(self) -> List[str]:
202
203
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
203
204
async def test_extract_file_pkg (
204
205
self ,
205
- extension_list : List [str ],
206
- inpath_return_values : Dict [str , bool ],
206
+ extension_list : list [str ],
207
+ inpath_return_values : dict [str , bool ],
207
208
mocker : MockerFixture ,
208
209
):
209
210
"""Test the pkg file extraction"""
@@ -234,12 +235,12 @@ def setup_class(cls):
234
235
shutil .copyfile (DOVECOT_FILE_PATH , cls .tempdir / "test.rpm" )
235
236
236
237
@pytest .fixture
237
- def extension_list (self ) -> List [str ]:
238
+ def extension_list (self ) -> list [str ]:
238
239
return self .extractor .file_extractors [self .extractor .extract_file_rpm ]
239
240
240
241
@pytest .mark .asyncio
241
242
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
242
- async def test_extract_file_rpm (self , extension_list : List [str ]):
243
+ async def test_extract_file_rpm (self , extension_list : list [str ]):
243
244
"""Test the rpm file extraction in windows with zstd"""
244
245
async for extracted_path in self .extract_files (
245
246
[f"test{ extension } " for extension in extension_list ]
@@ -256,12 +257,12 @@ def setup_method(self):
256
257
shutil .copyfile (self .tempdir / "test.deb" , self .tempdir / "test.ipk" )
257
258
258
259
@pytest .fixture
259
- def extension_list (self ) -> List [str ]:
260
+ def extension_list (self ) -> list [str ]:
260
261
return self .extractor .file_extractors [self .extractor .extract_file_deb ]
261
262
262
263
@pytest .mark .asyncio
263
264
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
264
- async def test_extract_file_deb (self , extension_list : List [str ]):
265
+ async def test_extract_file_deb (self , extension_list : list [str ]):
265
266
"""Test the deb file extraction"""
266
267
async for extracted_path in self .extract_files (
267
268
[f"test{ extension } " for extension in extension_list ]
@@ -272,7 +273,7 @@ async def test_extract_file_deb(self, extension_list: List[str]):
272
273
273
274
@pytest .mark .asyncio
274
275
async def test_extract_file_deb_no_tool (
275
- self , extension_list : List [str ], mocker : MockerFixture
276
+ self , extension_list : list [str ], mocker : MockerFixture
276
277
):
277
278
"""Test the deb file extraction with no extraction tool"""
278
279
@@ -303,12 +304,12 @@ def setup_method(self):
303
304
shutil .copyfile (IPK_FILE_PATH , self .tempdir / "test.ipk" )
304
305
305
306
@pytest .fixture
306
- def extension_list (self ) -> List [str ]:
307
+ def extension_list (self ) -> list [str ]:
307
308
return self .extractor .file_extractors [self .extractor .extract_file_deb ]
308
309
309
310
@pytest .mark .asyncio
310
311
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
311
- async def test_extract_file_ipk (self , extension_list : List [str ]):
312
+ async def test_extract_file_ipk (self , extension_list : list [str ]):
312
313
"""Test the ipk file extraction"""
313
314
async for extracted_path in self .extract_files (
314
315
[f"test{ extension } " for extension in extension_list ]
@@ -325,12 +326,12 @@ def setup_method(self):
325
326
shutil .copyfile (CAB_TEST_FILE_PATH , self .tempdir / "test.cab" )
326
327
327
328
@pytest .fixture
328
- def extension_list (self ) -> List [str ]:
329
+ def extension_list (self ) -> list [str ]:
329
330
return self .extractor .file_extractors [self .extractor .extract_file_cab ]
330
331
331
332
@pytest .mark .asyncio
332
333
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
333
- async def test_extract_file_cab (self , extension_list : List [str ]):
334
+ async def test_extract_file_cab (self , extension_list : list [str ]):
334
335
"""Test the cab file extraction"""
335
336
async for extracted_path in self .extract_files (
336
337
[f"test{ extension } " for extension in extension_list ]
@@ -339,7 +340,7 @@ async def test_extract_file_cab(self, extension_list: List[str]):
339
340
340
341
@pytest .mark .asyncio
341
342
async def test_extract_file_cab_no_cabextract (
342
- self , extension_list : List [str ], mocker : MockerFixture
343
+ self , extension_list : list [str ], mocker : MockerFixture
343
344
):
344
345
"""Test the cab file extraction with no extraction tool"""
345
346
@@ -365,14 +366,14 @@ class TestExtractFileZip(TestExtractorBase):
365
366
when the exe is a self-extracting zipfile"""
366
367
367
368
@pytest .fixture
368
- def extension_list (self ) -> List [str ]:
369
+ def extension_list (self ) -> list [str ]:
369
370
return list (
370
371
self .extractor .file_extractors [self .extractor .extract_file_apk ]
371
372
| self .extractor .file_extractors [self .extractor .extract_file_zip ]
372
373
)
373
374
374
375
@pytest .fixture (autouse = True )
375
- def setup_method (self , extension_list : List [str ]):
376
+ def setup_method (self , extension_list : list [str ]):
376
377
for filename in [f"test{ extension } " for extension in extension_list ]:
377
378
zippath = self .tempdir / filename
378
379
with ZipFile (zippath , "w" ) as zipfile :
@@ -391,8 +392,8 @@ def setup_method(self, extension_list: List[str]):
391
392
@pytest .mark .skipif (sys .version_info < (3 , 8 ), reason = "py3.7 fails sometimes" )
392
393
async def test_extract_file_zip (
393
394
self ,
394
- extension_list : List [str ],
395
- inpath_return_values : Dict [str , bool ],
395
+ extension_list : list [str ],
396
+ inpath_return_values : dict [str , bool ],
396
397
mocker : MockerFixture ,
397
398
):
398
399
"""Test the zip file extraction"""
0 commit comments