diff --git a/dojo/tools/factory.py b/dojo/tools/factory.py index 03ddec4e574..04930321c50 100644 --- a/dojo/tools/factory.py +++ b/dojo/tools/factory.py @@ -117,7 +117,7 @@ def requires_tool_type(scan_type): package_dir = str(Path(__file__).resolve().parent) for module_name in os.listdir(package_dir): # check if it's dir - if os.path.isdir(os.path.join(package_dir, module_name)): + if Path(os.path.join(package_dir, module_name)).is_dir(): try: # check if it's a Python module if find_spec(f"dojo.tools.{module_name}.parser"): diff --git a/dojo/utils.py b/dojo/utils.py index c9171348911..d30ef1ea63c 100644 --- a/dojo/utils.py +++ b/dojo/utils.py @@ -1383,7 +1383,7 @@ def get_page_items_and_count(request, items, page_size, prefix="", do_count=True def handle_uploaded_threat(f, eng): _name, extension = os.path.splitext(f.name) # Check if threat folder exist. - if not os.path.isdir(settings.MEDIA_ROOT + "/threat/"): + if not Path(settings.MEDIA_ROOT + "/threat/").is_dir(): # Create the folder Path(settings.MEDIA_ROOT + "/threat/").mkdir() with open(settings.MEDIA_ROOT + f"/threat/{eng.id}{extension}", diff --git a/ruff.toml b/ruff.toml index f073ee71e5d..7692186dda0 100644 --- a/ruff.toml +++ b/ruff.toml @@ -65,7 +65,7 @@ select = [ "TCH", "INT", "ARG003", "ARG004", "ARG005", - "PTH2", "PTH101", "PTH102", "PTH103", "PTH104", "PTH105", "PTH106", "PTH107", "PTH108", "PTH109", "PTH110", "PTH111", "PTH114", "PTH115", "PTH116", "PTH117", "PTH119", "PTH121", "PTH124", + "PTH2", "PTH101", "PTH102", "PTH103", "PTH104", "PTH105", "PTH106", "PTH107", "PTH108", "PTH109", "PTH110", "PTH111", "PTH112", "PTH114", "PTH115", "PTH116", "PTH117", "PTH119", "PTH121", "PTH124", "TD001", "TD004", "TD005", "PD", "PGH", diff --git a/tests/Import_scanner_test.py b/tests/Import_scanner_test.py index 34fe5e2b42c..f4305da2499 100644 --- a/tests/Import_scanner_test.py +++ b/tests/Import_scanner_test.py @@ -22,7 +22,7 @@ class ScannerTest(BaseTestCase): def setUp(self): super().setUp(self) self.repo_path = dir_path + "/scans" - if os.path.isdir(self.repo_path): + if Path(self.repo_path).is_dir(): shutil.rmtree(self.repo_path) Path(self.repo_path).mkdir() git.Repo.clone_from("https://github.com/DefectDojo/sample-scan-files", self.repo_path) diff --git a/unittests/test_factory.py b/unittests/test_factory.py index 4f268dee0b4..43fb5b54771 100644 --- a/unittests/test_factory.py +++ b/unittests/test_factory.py @@ -3,6 +3,7 @@ from importlib import import_module from importlib.util import find_spec from inspect import isclass +from pathlib import Path from dojo.models import Test, Test_Type from dojo.tools.factory import get_parser @@ -72,7 +73,7 @@ def test_parser_name_matches_module(self): for module_name in module_names: if module_name in excluded_parsers: continue - if os.path.isdir(os.path.join(package_dir, module_name)): + if Path(os.path.join(package_dir, module_name)).is_dir(): found = False if find_spec(f"dojo.tools.{module_name}.parser"): module = import_module(f"dojo.tools.{module_name}.parser") diff --git a/unittests/test_parsers.py b/unittests/test_parsers.py index 9e2ac077f14..9bf1af31332 100644 --- a/unittests/test_parsers.py +++ b/unittests/test_parsers.py @@ -66,7 +66,7 @@ def test_file_existence(self): with self.subTest(parser=parser_dir.name, category="testfiles"): scan_dir = os.path.join(basedir, "unittests", "scans", parser_dir.name) self.assertTrue( - os.path.isdir(scan_dir), + Path(scan_dir).is_dir(), f"Test files for unittest of parser '{scan_dir}' are missing or using different name", )