Skip to content

Increase Codefactor score #458

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

Merged
merged 4 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Provide pytest fixtures and other configuration for testing."""

from pathlib import Path

import pytest


@pytest.fixture(name="mock_github_output_file")
def fixture_mock_github_output_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""Mock the GitHub output file.

Args:
tmp_path (fixture): The temporary path fixture.
monkeypatch (fixture): The monkeypatch fixture.
"""
github_output_file = tmp_path / "github_output"
monkeypatch.setenv("GITHUB_OUTPUT", str(github_output_file))
return github_output_file
13 changes: 0 additions & 13 deletions tests/test_create_unique_testpypi_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,6 @@ def fixture_mock_pyproject_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch)
return pyproject_file


@pytest.fixture(name="mock_github_output_file")
def fixture_mock_github_output_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""Mock the GitHub output file.

Args:
tmp_path (fixture): The temporary path fixture.
monkeypatch (fixture): The monkeypatch fixture.
"""
github_output_file = tmp_path / "github_output"
monkeypatch.setenv("GITHUB_OUTPUT", str(github_output_file))
return github_output_file


def test_main(
mock_testpypi_server: MagicMock, # noqa: ARG001
mock_pyproject_file: Path,
Expand Down
13 changes: 0 additions & 13 deletions tests/test_find_unreleased_changelog_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,6 @@ def fixture_summary_file(tmp_path: Path) -> Path:
return tmp_path / "github_summary.txt"


@pytest.fixture(name="mock_github_output_file")
def fixture_mock_github_output_file(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""Mock the GitHub output file.

Args:
tmp_path (fixture): The temporary path fixture.
monkeypatch (fixture): The monkeypatch fixture.
"""
github_output_file = tmp_path / "github_output"
monkeypatch.setenv("GITHUB_OUTPUT", str(github_output_file))
return github_output_file


@pytest.fixture(name="mock_env_vars")
def fixture_mock_env_vars(
tmp_path: Path,
Expand Down
83 changes: 30 additions & 53 deletions tests/test_update_development_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Generator
from pathlib import Path
from typing import Any
from unittest.mock import call, MagicMock, patch

import pytest
Expand Down Expand Up @@ -191,6 +192,28 @@ def test_update_poetry_dependencies(
mock_subproc_call.assert_has_calls(expected_calls, any_order=True)


def _create_mock_pre_commit_autoupdate_call(repo_url: str) -> Any: # noqa: ANN401
"""Create a mock call for pre-commit autoupdate.

Args:
repo_url: The URL of the pre-commit repository.

Returns:
A call object representing the pre-commit autoupdate command.
"""
return call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
repo_url,
]
)


def test_update_pre_commit_dependencies(
repo_root_dir: Path,
monkeypatch: pytest.MonkeyPatch, # noqa: ARG001
Expand All @@ -213,61 +236,15 @@ def test_update_pre_commit_dependencies(
f"{repo_root_dir.resolve().as_posix()}",
]
),
call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
"https://github.com/pre-commit/pre-commit-hooks",
]
),
call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
"https://github.com/Mateusz-Grzelinski/actionlint-py",
]
),
call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
"https://github.com/lyz-code/yamlfix",
]
),
call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
"https://github.com/AleksaC/hadolint-py",
]
_create_mock_pre_commit_autoupdate_call(
"https://github.com/pre-commit/pre-commit-hooks"
),
call(
[
PYTHON_EXECUTABLE,
"-m",
"pre_commit",
"autoupdate",
"--freeze",
"--repo",
"https://github.com/astral-sh/ruff-pre-commit",
]
_create_mock_pre_commit_autoupdate_call(
"https://github.com/Mateusz-Grzelinski/actionlint-py"
),
_create_mock_pre_commit_autoupdate_call("https://github.com/lyz-code/yamlfix"),
_create_mock_pre_commit_autoupdate_call("https://github.com/AleksaC/hadolint-py"),
_create_mock_pre_commit_autoupdate_call("https://github.com/astral-sh/ruff-pre-commit"),
]
assert mock_subproc_call.call_count == 6
mock_subproc_call.assert_has_calls(expected_calls, any_order=True)
Expand Down
Loading