Skip to content

Commit 611c0bf

Browse files
refactor: update types syntax in test (#2394)
* Changed files * Update test_util.py * Update cve_scanner.py * Changed files * Update test_extractor.py * Update test_extractor.py * Revert "Update test_extractor.py" This reverts commit b541ece. * Update test_util.py * Update test_util.py * Revert default dict for now * isort linting * Update test_util.py * Reverting all changes to cve_scanner and test_util * Linting Co-authored-by: Terri Oda <[email protected]>
1 parent 0d44944 commit 611c0bf

File tree

11 files changed

+55
-50
lines changed

11 files changed

+55
-50
lines changed

cve_bin_tool/cve_scanner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def __init__(
6060

6161
def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
6262
"""Get CVEs against a specific version of a product.
63-
6463
Example:
6564
nvd.get_cves('haxx', 'curl', '7.34.0')
6665
"""

test/test_async_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"""
55
CVE-bin-tool async util tests
66
"""
7+
from __future__ import annotations
8+
79
import dataclasses
810
import subprocess
911
import unittest.mock
10-
from typing import Callable, Coroutine, Tuple
12+
from collections.abc import Coroutine
1113

1214
import pytest
1315

@@ -18,11 +20,11 @@
1820
class FakeProcess:
1921
returncode: int
2022

21-
async def communicate(self) -> Tuple[bytes, bytes]:
23+
async def communicate(self) -> tuple[bytes, bytes]:
2224
return b"", b""
2325

2426

25-
def mkexec(returncode: int) -> Callable[..., Coroutine[None, None, FakeProcess]]:
27+
def mkexec(returncode: int) -> callable[..., Coroutine[None, None, FakeProcess]]:
2628
async def return_fake_process(*args, **kwargs) -> FakeProcess:
2729
return FakeProcess(returncode=returncode)
2830

test/test_cvescanner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (C) 2021 Anthony Harrison
22
# SPDX-License-Identifier: GPL-3.0-or-later
3+
from __future__ import annotations
34

45
import pytest
56

test/test_data/grub2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (C) 2022 Orange
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4-
from typing import Dict, List
4+
from __future__ import annotations
55

6-
mapping_test_data: List[Dict] = []
6+
mapping_test_data: list[dict] = []
77
package_test_data = [
88
{
99
"url": "http://rpmfind.net/linux/opensuse/distribution/leap/15.5/repo/oss/aarch64/",

test/test_data/kerberos.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) 2021 Intel Corporation
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4-
from typing import Dict, List
4+
from __future__ import annotations
55

66
mapping_test_data = [
77
{
@@ -23,4 +23,4 @@
2323
],
2424
},
2525
]
26-
package_test_data: List[Dict] = []
26+
package_test_data: list[dict] = []

test/test_data/kerberos_5.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (C) 2021 Intel Corporation
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4-
from typing import Dict, List
4+
from __future__ import annotations
55

6-
mapping_test_data: List[Dict] = []
6+
mapping_test_data: list[dict] = []
77
package_test_data = [
88
{
99
"url": "http://mirror.centos.org/centos/7/os/x86_64/Packages/",

test/test_data/unbound.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (C) 2022 Orange
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

4-
from typing import Dict, List
4+
from __future__ import annotations
55

6-
mapping_test_data: List[Dict] = []
6+
mapping_test_data: list[dict] = []
77
package_test_data = [
88
{
99
"url": "http://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/aarch64/os/Packages/u/",

test/test_extractor.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

44
""" CVE Binary Tool tests for the extractor function """
5+
from __future__ import annotations
6+
57
import shutil
68
import sys
79
import tarfile
@@ -21,7 +23,6 @@
2123
ZST_FILE_PATH,
2224
download_file,
2325
)
24-
from typing import Dict, List
2526
from zipfile import ZipFile, ZipInfo
2627

2728
import pytest
@@ -63,12 +64,12 @@ async def extract_files(self, filenames):
6364
yield await ectx.aio_extract(str(self.tempdir / filename))
6465

6566
@pytest.fixture
66-
def extension_list(self) -> List[str]:
67+
def extension_list(self) -> list[str]:
6768
return []
6869

6970
@pytest.mark.asyncio
7071
@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]):
7273
"""Test handling of invalid files. No exceptions should be raised."""
7374
for extension in extension_list:
7475
filename = self.tempdir / f"empty-file{extension}"
@@ -99,11 +100,11 @@ def setup_method(self):
99100
tar.close()
100101

101102
@pytest.fixture
102-
def extension_list(self) -> List[str]:
103+
def extension_list(self) -> list[str]:
103104
return self.extractor.file_extractors[self.extractor.extract_file_tar]
104105

105106
@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]):
107108
"""Test the tar file extraction"""
108109
async for dir_path in self.extract_files(
109110
[f"test{extension}" for extension in extension_list]
@@ -129,12 +130,12 @@ def setup_class(cls):
129130
download_file(CURL_7_20_0_URL, cls.tempdir / "test.rpm")
130131

131132
@pytest.fixture
132-
def extension_list(self) -> List[str]:
133+
def extension_list(self) -> list[str]:
133134
return self.extractor.file_extractors[self.extractor.extract_file_rpm]
134135

135136
@pytest.mark.asyncio
136137
@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]):
138139
"""Test the rpm file extraction"""
139140
async for extracted_path in self.extract_files(
140141
[f"test{extension}" for extension in extension_list]
@@ -143,7 +144,7 @@ async def test_extract_file_rpm(self, extension_list: List[str]):
143144

144145
@pytest.mark.asyncio
145146
@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]):
147148
"""Test rpm extraction using rpmfile"""
148149
with unittest.mock.patch(
149150
"cve_bin_tool.async_utils.aio_inpath",
@@ -162,15 +163,15 @@ def setup_method(self):
162163
shutil.copyfile(ZST_FILE_PATH, self.tempdir / "test.zst")
163164

164165
@pytest.fixture
165-
def extension_list(self) -> List[str]:
166+
def extension_list(self) -> list[str]:
166167
return self.extractor.file_extractors[self.extractor.extract_file_zst]
167168

168169
@pytest.mark.asyncio
169170
@pytest.mark.skipif(sys.version_info < (3, 8), reason="py3.7 fails sometimes")
170171
@pytest.mark.skipif(
171172
sys.platform == "win32", reason="windows zst support incomplete"
172173
)
173-
async def test_extract_file_zst(self, extension_list: List[str]):
174+
async def test_extract_file_zst(self, extension_list: list[str]):
174175
"""Test the zst file extraction"""
175176
async for extracted_path in self.extract_files(
176177
[f"test{extension}" for extension in extension_list]
@@ -188,7 +189,7 @@ def setup_method(self):
188189
shutil.copyfile(PKG_FILE_PATH, self.tempdir / "test.pkg")
189190

190191
@pytest.fixture
191-
def extension_list(self) -> List[str]:
192+
def extension_list(self) -> list[str]:
192193
return self.extractor.file_extractors[self.extractor.extract_file_pkg]
193194

194195
@pytest.mark.parametrize(
@@ -202,8 +203,8 @@ def extension_list(self) -> List[str]:
202203
@pytest.mark.skipif(sys.version_info < (3, 8), reason="py3.7 fails sometimes")
203204
async def test_extract_file_pkg(
204205
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],
207208
mocker: MockerFixture,
208209
):
209210
"""Test the pkg file extraction"""
@@ -234,12 +235,12 @@ def setup_class(cls):
234235
shutil.copyfile(DOVECOT_FILE_PATH, cls.tempdir / "test.rpm")
235236

236237
@pytest.fixture
237-
def extension_list(self) -> List[str]:
238+
def extension_list(self) -> list[str]:
238239
return self.extractor.file_extractors[self.extractor.extract_file_rpm]
239240

240241
@pytest.mark.asyncio
241242
@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]):
243244
"""Test the rpm file extraction in windows with zstd"""
244245
async for extracted_path in self.extract_files(
245246
[f"test{extension}" for extension in extension_list]
@@ -256,12 +257,12 @@ def setup_method(self):
256257
shutil.copyfile(self.tempdir / "test.deb", self.tempdir / "test.ipk")
257258

258259
@pytest.fixture
259-
def extension_list(self) -> List[str]:
260+
def extension_list(self) -> list[str]:
260261
return self.extractor.file_extractors[self.extractor.extract_file_deb]
261262

262263
@pytest.mark.asyncio
263264
@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]):
265266
"""Test the deb file extraction"""
266267
async for extracted_path in self.extract_files(
267268
[f"test{extension}" for extension in extension_list]
@@ -272,7 +273,7 @@ async def test_extract_file_deb(self, extension_list: List[str]):
272273

273274
@pytest.mark.asyncio
274275
async def test_extract_file_deb_no_tool(
275-
self, extension_list: List[str], mocker: MockerFixture
276+
self, extension_list: list[str], mocker: MockerFixture
276277
):
277278
"""Test the deb file extraction with no extraction tool"""
278279

@@ -303,12 +304,12 @@ def setup_method(self):
303304
shutil.copyfile(IPK_FILE_PATH, self.tempdir / "test.ipk")
304305

305306
@pytest.fixture
306-
def extension_list(self) -> List[str]:
307+
def extension_list(self) -> list[str]:
307308
return self.extractor.file_extractors[self.extractor.extract_file_deb]
308309

309310
@pytest.mark.asyncio
310311
@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]):
312313
"""Test the ipk file extraction"""
313314
async for extracted_path in self.extract_files(
314315
[f"test{extension}" for extension in extension_list]
@@ -325,12 +326,12 @@ def setup_method(self):
325326
shutil.copyfile(CAB_TEST_FILE_PATH, self.tempdir / "test.cab")
326327

327328
@pytest.fixture
328-
def extension_list(self) -> List[str]:
329+
def extension_list(self) -> list[str]:
329330
return self.extractor.file_extractors[self.extractor.extract_file_cab]
330331

331332
@pytest.mark.asyncio
332333
@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]):
334335
"""Test the cab file extraction"""
335336
async for extracted_path in self.extract_files(
336337
[f"test{extension}" for extension in extension_list]
@@ -339,7 +340,7 @@ async def test_extract_file_cab(self, extension_list: List[str]):
339340

340341
@pytest.mark.asyncio
341342
async def test_extract_file_cab_no_cabextract(
342-
self, extension_list: List[str], mocker: MockerFixture
343+
self, extension_list: list[str], mocker: MockerFixture
343344
):
344345
"""Test the cab file extraction with no extraction tool"""
345346

@@ -365,14 +366,14 @@ class TestExtractFileZip(TestExtractorBase):
365366
when the exe is a self-extracting zipfile"""
366367

367368
@pytest.fixture
368-
def extension_list(self) -> List[str]:
369+
def extension_list(self) -> list[str]:
369370
return list(
370371
self.extractor.file_extractors[self.extractor.extract_file_apk]
371372
| self.extractor.file_extractors[self.extractor.extract_file_zip]
372373
)
373374

374375
@pytest.fixture(autouse=True)
375-
def setup_method(self, extension_list: List[str]):
376+
def setup_method(self, extension_list: list[str]):
376377
for filename in [f"test{extension}" for extension in extension_list]:
377378
zippath = self.tempdir / filename
378379
with ZipFile(zippath, "w") as zipfile:
@@ -391,8 +392,8 @@ def setup_method(self, extension_list: List[str]):
391392
@pytest.mark.skipif(sys.version_info < (3, 8), reason="py3.7 fails sometimes")
392393
async def test_extract_file_zip(
393394
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],
396397
mocker: MockerFixture,
397398
):
398399
"""Test the zip file extraction"""

test/test_format_checker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
"""
55
CVE-bin-tool Format Checker tests
66
"""
7+
from __future__ import annotations
8+
79
import re
810
from pathlib import Path
9-
from typing import List
1011

1112
import pytest
1213
from pytest_mock import MockerFixture
@@ -68,13 +69,13 @@ def checkers_array(self):
6869
return checkers_array
6970

7071
@pytest.fixture
71-
def shape_list(self, checkers_array: List[List[str]]):
72+
def shape_list(self, checkers_array: list[list[str]]):
7273
shape_list = format_checkers.max_checker_length(checkers_array)
7374
assert shape_list == [15, 7, 16, 7, 7, 13, 15]
7475
return shape_list
7576

7677
@pytest.fixture
77-
def checkers_markdown(self, checkers_array: List[List[str]], shape_list: List[int]):
78+
def checkers_markdown(self, checkers_array: list[list[str]], shape_list: list[int]):
7879
checkers_markdown = format_checkers.reformat_checkers(
7980
checkers_array, shape_list
8081
)

test/test_sbom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright (C) 2021 Anthony Harrison
22
# SPDX-License-Identifier: GPL-3.0-or-later
3+
from __future__ import annotations
34

45
from pathlib import Path
5-
from typing import Dict
66

77
import pytest
88

@@ -70,7 +70,7 @@ def test_invalid_type(self, filename: str, sbom_type: str):
7070
),
7171
)
7272
def test_valid_spdx_file(
73-
self, filename: str, spdx_parsed_data: Dict[ProductInfo, TriageData]
73+
self, filename: str, spdx_parsed_data: dict[ProductInfo, TriageData]
7474
):
7575
sbom_engine = SBOMManager(filename, sbom_type="spdx")
7676
assert sbom_engine.scan_file() == spdx_parsed_data
@@ -84,7 +84,7 @@ def test_valid_spdx_file(
8484
),
8585
)
8686
def test_valid_cyclonedx_file(
87-
self, filename: str, cyclonedx_parsed_data: Dict[ProductInfo, TriageData]
87+
self, filename: str, cyclonedx_parsed_data: dict[ProductInfo, TriageData]
8888
):
8989
sbom_engine = SBOMManager(filename, sbom_type="cyclonedx")
9090
assert sbom_engine.scan_file() == cyclonedx_parsed_data
@@ -94,7 +94,7 @@ def test_valid_cyclonedx_file(
9494
((str(SBOM_PATH / "swid_test.xml"), PARSED_SBOM_DATA),),
9595
)
9696
def test_valid_swid_file(
97-
self, filename: str, swid_parsed_data: Dict[ProductInfo, TriageData]
97+
self, filename: str, swid_parsed_data: dict[ProductInfo, TriageData]
9898
):
9999
sbom_engine = SBOMManager(filename, sbom_type="swid")
100100
assert sbom_engine.scan_file() == swid_parsed_data

0 commit comments

Comments
 (0)