Skip to content

Commit 6500898

Browse files
committed
tests(refactor[typing]): Replace Any in CLI/config fixtures
why: Improve type precision for JSON payload checks and config fixtures in tests. what: - Add JSON/config type aliases for CLI plan tests - Tighten fixture protocol and config writer entry types
1 parent 3d5b488 commit 6500898

3 files changed

Lines changed: 23 additions & 12 deletions

File tree

tests/test_cli.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616
from vcspull.__about__ import __version__
1717
from vcspull._internal.private_path import PrivatePath
1818
from vcspull.cli import cli
19-
from vcspull.cli._output import PlanAction, PlanEntry, PlanResult, PlanSummary
19+
from vcspull.cli._output import (
20+
JsonValue,
21+
PlanAction,
22+
PlanEntry,
23+
PlanResult,
24+
PlanSummary,
25+
)
2026
from vcspull.cli.sync import EXIT_ON_ERROR_MSG, NO_REPOS_FOR_TERM_MSG
2127

2228
sync_module = importlib.import_module("vcspull.cli.sync")
2329

30+
RepoConfig: t.TypeAlias = dict[str, str | dict[str, str]]
31+
ConfigData: t.TypeAlias = dict[str, dict[str, RepoConfig]]
32+
OperationSubset: t.TypeAlias = dict[str, JsonValue]
33+
RepoRecord: t.TypeAlias = dict[str, str]
34+
2435
if t.TYPE_CHECKING:
2536
from typing import TypeAlias
2637

@@ -652,7 +663,7 @@ def test_sync_dry_run_plan_human(
652663
if set_no_color:
653664
monkeypatch.setenv("NO_COLOR", "1")
654665

655-
config: dict[str, dict[str, dict[str, t.Any]]] = {"~/github_projects/": {}}
666+
config: ConfigData = {"~/github_projects/": {}}
656667
for name in repository_names:
657668
config["~/github_projects/"][name] = {
658669
"url": f"git+file://{git_repo.path}",
@@ -697,7 +708,7 @@ def test_sync_dry_run_plan_human(
697708
errors=sum(entry.action is PlanAction.ERROR for entry in plan_entries),
698709
)
699710

700-
async def _fake_plan(*args: t.Any, **kwargs: t.Any) -> PlanResult:
711+
async def _fake_plan(*args: object, **kwargs: object) -> PlanResult:
701712
return PlanResult(entries=plan_entries, summary=computed_summary)
702713

703714
monkeypatch.setattr(sync_module, "_build_plan_result_async", _fake_plan)
@@ -728,7 +739,7 @@ class DryRunPlanMachineFixture(t.NamedTuple):
728739
pre_sync: bool = True
729740
plan_entries: list[PlanEntry] | None = None
730741
plan_summary: PlanSummary | None = None
731-
expected_operation_subset: dict[str, t.Any] | None = None
742+
expected_operation_subset: OperationSubset | None = None
732743

733744

734745
DRY_RUN_PLAN_MACHINE_FIXTURES: list[DryRunPlanMachineFixture] = [
@@ -835,7 +846,7 @@ def test_sync_dry_run_plan_machine(
835846
pre_sync: bool,
836847
plan_entries: list[PlanEntry] | None,
837848
plan_summary: PlanSummary | None,
838-
expected_operation_subset: dict[str, t.Any] | None,
849+
expected_operation_subset: OperationSubset | None,
839850
tmp_path: pathlib.Path,
840851
capsys: pytest.CaptureFixture[str],
841852
monkeypatch: pytest.MonkeyPatch,
@@ -846,7 +857,7 @@ def test_sync_dry_run_plan_machine(
846857
"""Validate machine-readable plan parity."""
847858
monkeypatch.setenv("NO_COLOR", "1")
848859

849-
config: dict[str, dict[str, dict[str, t.Any]]] = {"~/github_projects/": {}}
860+
config: ConfigData = {"~/github_projects/": {}}
850861
for name in repository_names:
851862
config["~/github_projects/"][name] = {
852863
"url": f"git+file://{git_repo.path}",
@@ -889,7 +900,7 @@ def test_sync_dry_run_plan_machine(
889900
errors=sum(entry.action is PlanAction.ERROR for entry in plan_entries),
890901
)
891902

892-
async def _fake_plan(*args: t.Any, **kwargs: t.Any) -> PlanResult:
903+
async def _fake_plan(*args: object, **kwargs: object) -> PlanResult:
893904
return PlanResult(entries=plan_entries, summary=computed_summary)
894905

895906
monkeypatch.setattr(sync_module, "_build_plan_result_async", _fake_plan)
@@ -924,7 +935,7 @@ async def _fake_plan(*args: t.Any, **kwargs: t.Any) -> PlanResult:
924935
assert summary["errors"] == expected_summary["errors"]
925936

926937
if mode == "json" and expected_operation_subset:
927-
operations: list[dict[str, t.Any]] = []
938+
operations: list[dict[str, JsonValue]] = []
928939
for workspace in payload["workspaces"]:
929940
operations.extend(workspace["operations"])
930941
assert operations, "Expected at least one operation payload"
@@ -1005,12 +1016,12 @@ def test_sync_human_output_redacts_repo_paths(
10051016
)
10061017

10071018
def _fake_filter_repos(
1008-
_configs: list[dict[str, t.Any]],
1019+
_configs: list[RepoRecord],
10091020
*,
10101021
path: str | None = None,
10111022
vcs_url: str | None = None,
10121023
name: str | None = None,
1013-
) -> list[dict[str, t.Any]]:
1024+
) -> list[RepoRecord]:
10141025
if name and name != repo_config["name"]:
10151026
return []
10161027
if path and path != repo_config["path"]:

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __call__(
2424
content: str,
2525
path: str = "randomdir",
2626
filename: str = "randomfilename.yaml",
27-
) -> tuple[pathlib.Path, list[t.Any | pathlib.Path], list[ConfigDict]]:
27+
) -> tuple[pathlib.Path, list[pathlib.Path], list[ConfigDict]]:
2828
"""Callable function type signature for load_yaml pytest fixture."""
2929
...
3030

tests/test_config_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
if t.TYPE_CHECKING:
1313
import pathlib
1414

15-
FixtureEntry = tuple[str, dict[str, t.Any]]
15+
FixtureEntry = tuple[str, dict[str, dict[str, str]]]
1616

1717

1818
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)