Skip to content

Commit

Permalink
Address some of the ruff PTH118 exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shatakshiiii committed May 27, 2024
1 parent b15e552 commit a4cd644
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion src/ansible_navigator/actions/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 2 additions & 1 deletion src/ansible_navigator/runner/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import tempfile

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

Expand Down Expand Up @@ -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":
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/actions/collections/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

from collections.abc import Generator
from pathlib import Path

import pytest

Expand Down Expand Up @@ -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 = {
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/actions/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os

from collections.abc import Generator
from pathlib import Path

import pytest

Expand All @@ -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 = (
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/actions/inventory/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/actions/replay/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 9 additions & 11 deletions tests/integration/actions/run/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
4 changes: 1 addition & 3 deletions tests/integration/test_stdout_exit_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

import os

from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any
Expand All @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/configuration_subsystem/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os

from copy import deepcopy
from pathlib import Path

import pytest

Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit a4cd644

Please sign in to comment.