Skip to content

Commit 6c13a9d

Browse files
authored
refactor(format_checkers): use pathlib instead of os.path (#1731)
1 parent cc58d07 commit 6c13a9d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cve_bin_tool/format_checkers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
"""To reformat checkers table when cve_bin_tool/checkers/__init__.py is updated."""
55

6-
import os
76
import re
7+
from pathlib import Path
88
from typing import List
99

1010
from cve_bin_tool import checkers
@@ -100,18 +100,20 @@ def update_allowed_words(checkers_array: List[str], file_path: str) -> None:
100100
checkers_array.sort()
101101
update_allowed_words(
102102
checkers_array,
103-
file_path=os.path.join(
104-
os.path.abspath("."), ".github", "actions", "spelling", "allow.txt"
105-
),
103+
file_path=Path(".").resolve()
104+
/ ".github"
105+
/ "actions"
106+
/ "spelling"
107+
/ "allow.txt",
106108
)
107109
checkers_array = reshape_list(checkers_array)
108110
shape_list = max_checker_length(checkers_array)
109111
checkers_markdown = reformat_checkers(checkers_array, shape_list)
110112
update_checker_table(
111-
file_path=os.path.join(os.path.abspath("."), "README.md"),
113+
file_path=Path(".").resolve() / "README.md",
112114
markdown=checkers_markdown,
113115
)
114116
update_checker_table(
115-
file_path=os.path.join(os.path.abspath("."), "doc", "MANUAL.md"),
117+
file_path=Path(".").resolve() / "doc" / "MANUAL.md",
116118
markdown=checkers_markdown,
117119
)

test/test_format_checker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CVE-bin-tool Format Checker tests
66
"""
77
import re
8-
from os.path import dirname, join
8+
from pathlib import Path
99
from typing import List
1010

1111
import pytest
@@ -19,7 +19,7 @@ class TestFormatCheckers:
1919

2020
@classmethod
2121
def setup_class(cls):
22-
cls.mock_path_dir = join(dirname(__file__), "format_checkers")
22+
cls.mock_path_dir = Path(__file__).parent / "format_checkers"
2323
cls.mock_checkers = [
2424
"libssh2",
2525
"polarssl_fedora",
@@ -37,7 +37,7 @@ def setup_class(cls):
3737
@pytest.mark.asyncio
3838
async def test_update_allowed_words(self, mocker: MockerFixture):
3939
"""Tests the update_allowed_words function"""
40-
file_path = join(self.mock_path_dir, "allow.txt")
40+
file_path = self.mock_path_dir / "allow.txt"
4141

4242
mocked_file = mocker.patch(
4343
"cve_bin_tool.format_checkers.open", mocker.mock_open()
@@ -83,7 +83,7 @@ def checkers_markdown(self, checkers_array: List[List[str]], shape_list: List[in
8383
def test_reformat_checkers(self, checkers_markdown, mocker: MockerFixture):
8484
"""Tests the reformat_checkers function"""
8585

86-
file_path = join(self.mock_path_dir, "checkers.md")
86+
file_path = self.mock_path_dir / "checkers.md"
8787

8888
mocked_file = mocker.patch(
8989
"cve_bin_tool.format_checkers.open",

0 commit comments

Comments
 (0)