Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address ruff PTH118: part1 #1801

Merged
merged 7 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansible_navigator/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def oxfordcomma(listed: Iterable[bool | str | Path], condition: str) -> str:
return f"{', '.join(str(x) for x in listed[:-1])} {condition} {listed[-1]}"


def expand_path(path: str) -> Path:
def expand_path(path: str | Path) -> Path:
"""Resolve a path.

:param path: The file path to resolve
Expand Down
9 changes: 3 additions & 6 deletions tests/defaults.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
"""Constants with default values used throughout the tests."""

import os

from enum import Enum
from pathlib import Path
from typing import Any

from ansible_navigator.utils.functions import expand_path


FIXTURES_DIR = expand_path(os.path.join(os.path.dirname(__file__), "fixtures"))
FIXTURES_COLLECTION_DIR = expand_path(
os.path.join(os.path.dirname(__file__), "fixtures", "common", "collections"),
)
FIXTURES_DIR = expand_path(Path(__file__).parent / "fixtures")
FIXTURES_COLLECTION_DIR = expand_path(Path(__file__).parent / "fixtures" / "common" / "collections")
FIXTURES_COLLECTION_PATH = FIXTURES_COLLECTION_DIR


Expand Down
7 changes: 6 additions & 1 deletion tests/integration/_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import shlex

from enum import Enum
from typing import TYPE_CHECKING
from typing import NamedTuple


if TYPE_CHECKING:
from pathlib import Path


class SearchFor(Enum):
"""An enum for response search types."""

Expand All @@ -20,7 +25,7 @@ class Command(NamedTuple):
"""Command details."""

execution_environment: bool
cmdline: str | None = None
cmdline: str | Path | None = None
command: str = "ansible-navigator"
format_: str | None = None
log_level: str = "debug"
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/actions/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,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 = FIXTURES_DIR / "integration" / "actions" / "config"
CONFIG_FIXTURE = TEST_FIXTURE_DIR / "ansible.cfg"


base_steps = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
),
UiTestStep(user_input=":back", comment="return to welcome screen"),
UiTestStep(
user_input=":config -c " + CONFIG_FIXTURE,
user_input=":config -c " + str(CONFIG_FIXTURE),
comment="enter config from welcome screen, custom config, (no ee)",
present=["Yaml filename extensions", "['.os2']"],
),
Expand Down
7 changes: 1 addition & 6 deletions tests/integration/actions/lint/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
from collections.abc import Generator


LINT_FIXTURES = os.path.join(
FIXTURES_DIR,
"integration",
"actions",
"lint",
)
LINT_FIXTURES = FIXTURES_DIR / "integration" / "actions" / "lint"


class BaseClass:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tests for lint (with no errors) from CLI, interactive, with an EE."""

import os

import pytest

from tests.integration._interactions import Command
Expand All @@ -15,10 +13,7 @@

CLI = Command(
subcommand="lint",
cmdline=os.path.join(
LINT_FIXTURES,
"no_errors",
),
cmdline=LINT_FIXTURES / "no_errors",
execution_environment=True,
).join()

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/actions/lint/test_stdout_tmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
comment="lint stdout with no errors",
user_input=Command(
subcommand="lint",
cmdline=os.path.join(LINT_FIXTURES, "no_errors"),
cmdline=LINT_FIXTURES / "no_errors",
mode="stdout",
execution_environment=True,
).join(),
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/actions/run/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@


# 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 = 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 = FIXTURES_DIR / "common" / "collections"
PLAYBOOK_COLLECTION = "company_name.coll_1.playbook_1"

base_steps = (
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/actions/run_unicode/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@


# run playbook
run_fixture_dir = os.path.join(FIXTURES_DIR, "integration", "actions", "run_unicode")
inventory_path = os.path.join(run_fixture_dir, "inventory")
playbook_path = os.path.join(run_fixture_dir, "site.yaml")
run_fixture_dir = FIXTURES_DIR / "integration" / "actions" / "run_unicode"
inventory_path = run_fixture_dir / "inventory"
playbook_path = run_fixture_dir / "site.yaml"

base_steps = (
UiTestStep(user_input=":0", comment="play-1 details"),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/actions/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.integration._tmux_session import TmuxSession


TEST_FIXTURE_DIR = os.path.join(FIXTURES_DIR, "integration/actions/settings")
TEST_FIXTURE_DIR = FIXTURES_DIR / "integration/actions/settings"

base_steps = (
UiTestStep(user_input=":f App", comment="filter for app settings"),
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/actions/templar/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@


# 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 = FIXTURES_DIR / "integration" / "actions" / "run"
inventory_path = run_fixture_dir / "inventory"
playbook_path = run_fixture_dir / "site.yaml"

base_steps = (
UiTestStep(user_input=":0", comment="play-1 details"),
Expand Down
8 changes: 3 additions & 5 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 = FIXTURES_DIR / "integration" / "stdout_exit_codes" / "site.yml"


@pytest.fixture(name="params")
Expand Down Expand Up @@ -120,7 +118,7 @@ class StdoutTest(NamedTuple):
),
StdoutTest(
action_name="run",
action_params=(("playbook", PLAYBOOK), ("playbook_artifact_enable", False)),
action_params=(("playbook", str(PLAYBOOK)), ("playbook_artifact_enable", False)),
present="success",
return_code=0,
),
Expand Down Expand Up @@ -206,7 +204,7 @@ def command(self) -> list[str]:
name="0",
comment="run pass",
subcommand="run",
params=[PLAYBOOK],
params=[str(PLAYBOOK)],
return_code=0,
ansible_stdout="ok=1",
ansible_stderr="",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/configuration_subsystem/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ansible_navigator.utils.definitions import LogMessage


TEST_FIXTURE_DIR = os.path.join(FIXTURES_DIR, "unit", "configuration_subsystem")
TEST_FIXTURE_DIR = FIXTURES_DIR / "unit" / "configuration_subsystem"


class GenerateConfigResponse(NamedTuple):
Expand Down
Loading