From a4cd644975ec38880a8351c58ed16c4d69a4a3fe Mon Sep 17 00:00:00 2001 From: shatakshiiii Date: Thu, 23 May 2024 14:56:30 +0530 Subject: [PATCH] Address some of the ruff PTH118 exceptions --- pyproject.toml | 1 - src/ansible_navigator/actions/collections.py | 3 ++- src/ansible_navigator/runner/base.py | 3 ++- tests/integration/actions/collections/base.py | 3 ++- tests/integration/actions/config/base.py | 5 +++-- tests/integration/actions/inventory/base.py | 6 +++--- tests/integration/actions/replay/base.py | 6 +++--- tests/integration/actions/run/base.py | 20 +++++++++---------- tests/integration/test_stdout_exit_codes.py | 4 +--- .../configuration_subsystem/test_internals.py | 5 +++-- 10 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9cf3b7c04..547f6d8f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -311,7 +311,6 @@ ignore = [ 'PTH111', # `os.path.expanduser()` should be replaced by `Path.expanduser()` 'PTH113', # `os.path.isfile()` should be replaced by `Path.is_file()` 'PTH116', # `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` - 'PTH118', # `os.path.join()` should be replaced by `Path` with `/` operator 'PTH119', # `os.path.basename()` should be replaced by `Path.name` 'PTH120', # `os.path.dirname()` should be replaced by `Path.parent` 'PTH122', # `os.path.splitext()` should be replaced by `Path.suffix` diff --git a/src/ansible_navigator/actions/collections.py b/src/ansible_navigator/actions/collections.py index 1f4de0d3e..6adbfa154 100644 --- a/src/ansible_navigator/actions/collections.py +++ b/src/ansible_navigator/actions/collections.py @@ -427,7 +427,8 @@ def _run_runner(self) -> None: kwargs["host_cwd"] = playbook_dir - self._adjacent_collection_dir = os.path.join(playbook_dir, "collections") + self._adjacent_collection_dir = Path(playbook_dir) / "collections" + cache_path = self._args.internals.cache_path pass_through_arg = [ diff --git a/src/ansible_navigator/runner/base.py b/src/ansible_navigator/runner/base.py index 26baf6777..913e091d7 100644 --- a/src/ansible_navigator/runner/base.py +++ b/src/ansible_navigator/runner/base.py @@ -11,6 +11,7 @@ import sys import tempfile +from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -125,7 +126,7 @@ def __init__( if self._host_cwd: # ensure the CWD ends with a trailing slash - host_cwd = os.path.join(self._host_cwd, "") + host_cwd = Path(self._host_cwd) / "" self._runner_args["host_cwd"] = host_cwd if self._navigator_mode == "stdout": diff --git a/tests/integration/actions/collections/base.py b/tests/integration/actions/collections/base.py index 76dfae9a1..12edc8b7e 100644 --- a/tests/integration/actions/collections/base.py +++ b/tests/integration/actions/collections/base.py @@ -4,6 +4,7 @@ import os from collections.abc import Generator +from pathlib import Path import pytest @@ -106,7 +107,7 @@ def fixture_tmux_session( os.makedirs(tmp_coll_dir, exist_ok=True) copytree( FIXTURES_COLLECTION_DIR, - os.path.join(tmp_coll_dir, "collections"), + Path(tmp_coll_dir) / "collections", dirs_exist_ok=True, ) params: TmuxSessionKwargs = { diff --git a/tests/integration/actions/config/base.py b/tests/integration/actions/config/base.py index 2d1ad17d2..c377df35c 100644 --- a/tests/integration/actions/config/base.py +++ b/tests/integration/actions/config/base.py @@ -4,6 +4,7 @@ import os from collections.abc import Generator +from pathlib import Path import pytest @@ -15,8 +16,8 @@ from tests.integration._tmux_session import TmuxSession -TEST_FIXTURE_DIR = os.path.join(FIXTURES_DIR, "integration", "actions", "config") -CONFIG_FIXTURE = os.path.join(TEST_FIXTURE_DIR, "ansible.cfg") +TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / "actions" / "config" +CONFIG_FIXTURE = Path(TEST_FIXTURE_DIR) / "ansible.cfg" base_steps = ( diff --git a/tests/integration/actions/inventory/base.py b/tests/integration/actions/inventory/base.py index 8c39e027c..d949f8bde 100644 --- a/tests/integration/actions/inventory/base.py +++ b/tests/integration/actions/inventory/base.py @@ -16,9 +16,9 @@ from tests.integration._tmux_session import TmuxSession -TEST_FIXTURE_DIR = os.path.join(FIXTURES_DIR, "integration", "actions", "inventory") -ANSIBLE_INVENTORY_FIXTURE_DIR = os.path.join(TEST_FIXTURE_DIR, "ansible_inventory", "inventory.yml") -TEST_CONFIG_FILE = os.path.join(TEST_FIXTURE_DIR, "ansible-navigator.yml") +TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration" / "actions" / "inventory" +ANSIBLE_INVENTORY_FIXTURE_DIR = Path(TEST_FIXTURE_DIR) / "ansible_inventory" / "inventory.yml" +TEST_CONFIG_FILE = Path(TEST_FIXTURE_DIR) / "ansible-navigator.yml" base_steps = ( diff --git a/tests/integration/actions/replay/base.py b/tests/integration/actions/replay/base.py index f5e83300c..088f13929 100644 --- a/tests/integration/actions/replay/base.py +++ b/tests/integration/actions/replay/base.py @@ -14,9 +14,9 @@ from tests.integration._tmux_session import TmuxSession -TEST_FIXTURE_DIR = os.path.join(FIXTURES_DIR, "integration/actions/replay") -PLAYBOOK_ARTIFACT = os.path.join(TEST_FIXTURE_DIR, "playbook-artifact.json") -TEST_CONFIG_FILE = os.path.join(TEST_FIXTURE_DIR, "ansible-navigator.yml") +TEST_FIXTURE_DIR = Path(FIXTURES_DIR) / "integration/actions/replay" +PLAYBOOK_ARTIFACT = Path(TEST_FIXTURE_DIR) / "playbook-artifact.json" +TEST_CONFIG_FILE = Path(TEST_FIXTURE_DIR) / "ansible-navigator.yml" class BaseClass: diff --git a/tests/integration/actions/run/base.py b/tests/integration/actions/run/base.py index 795d010af..2bc8aea32 100644 --- a/tests/integration/actions/run/base.py +++ b/tests/integration/actions/run/base.py @@ -4,30 +4,28 @@ import difflib import os - +from pathlib import Path from typing import TYPE_CHECKING import pytest from tests.defaults import FIXTURES_DIR -from tests.integration._common import retrieve_fixture_for_step -from tests.integration._common import update_fixtures -from tests.integration._interactions import SearchFor -from tests.integration._interactions import UiTestStep -from tests.integration._tmux_session import TmuxSession -from tests.integration._tmux_session import TmuxSessionKwargs - +from tests.integration._common import (retrieve_fixture_for_step, + update_fixtures) +from tests.integration._interactions import SearchFor, UiTestStep +from tests.integration._tmux_session import TmuxSession, TmuxSessionKwargs if TYPE_CHECKING: from collections.abc import Generator # run playbook -run_fixture_dir = os.path.join(FIXTURES_DIR, "integration", "actions", "run") -inventory_path = os.path.join(run_fixture_dir, "inventory") -playbook_path = os.path.join(run_fixture_dir, "site.yaml") +run_fixture_dir = Path(FIXTURES_DIR) / "integration" / "actions" / "run" +inventory_path = run_fixture_dir / "inventory" +playbook_path = run_fixture_dir / "site.yaml" common_fixture_dir = os.path.join(FIXTURES_DIR, "common", "collections") +common_fixture_dir = Path(FIXTURES_DIR) / "common" / "collections" PLAYBOOK_COLLECTION = "company_name.coll_1.playbook_1" base_steps = ( diff --git a/tests/integration/test_stdout_exit_codes.py b/tests/integration/test_stdout_exit_codes.py index 51b85059c..82189c85b 100644 --- a/tests/integration/test_stdout_exit_codes.py +++ b/tests/integration/test_stdout_exit_codes.py @@ -2,8 +2,6 @@ from __future__ import annotations -import os - from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -24,7 +22,7 @@ from ._action_run_test import ActionRunTest -PLAYBOOK = os.path.join(FIXTURES_DIR, "integration", "stdout_exit_codes", "site.yml") +PLAYBOOK = Path(FIXTURES_DIR) / "integration" / "stdout_exit_codes" / "site.yml" @pytest.fixture(name="params") diff --git a/tests/unit/configuration_subsystem/test_internals.py b/tests/unit/configuration_subsystem/test_internals.py index 7090b66eb..9069ebf37 100644 --- a/tests/unit/configuration_subsystem/test_internals.py +++ b/tests/unit/configuration_subsystem/test_internals.py @@ -3,6 +3,7 @@ import os from copy import deepcopy +from pathlib import Path import pytest @@ -29,7 +30,7 @@ def test_settings_file_path_file_system(monkeypatch: pytest.MonkeyPatch) -> None functionality in tests """ settings_file = "ansible-navigator.yml" - settings_file_path = os.path.join(TEST_FIXTURE_DIR, settings_file) + settings_file_path = Path(TEST_FIXTURE_DIR) / settings_file args = deepcopy(NavigatorConfiguration) args.internals.initializing = True args.application_version = "test" @@ -50,7 +51,7 @@ def test_settings_file_path_environment_variable(monkeypatch: pytest.MonkeyPatch functionality in tests """ settings_file = "ansible-navigator.yml" - settings_file_path = os.path.join(TEST_FIXTURE_DIR, settings_file) + settings_file_path = Path(TEST_FIXTURE_DIR) / settings_file monkeypatch.setenv("ANSIBLE_NAVIGATOR_CONFIG", settings_file_path) args = deepcopy(NavigatorConfiguration) args.internals.initializing = True