Skip to content

Commit e08d187

Browse files
committed
tests/cli(fmt): capture workspace root normalization gap
1 parent 4ca8159 commit e08d187

1 file changed

Lines changed: 75 additions & 2 deletions

File tree

tests/cli/test_fmt.py

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from __future__ import annotations
44

55
import logging
6+
import pathlib
67
import typing as t
8+
from typing import ClassVar
79

810
import pytest
911
import yaml
1012

1113
from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config
1214

1315
if t.TYPE_CHECKING:
14-
import pathlib
15-
1616
from _pytest.logging import LogCaptureFixture
1717

1818

@@ -65,6 +65,79 @@ def test_both_url_and_repo(self) -> None:
6565
class TestFormatConfig:
6666
"""Test configuration formatting."""
6767

68+
class WorkspaceRootFixture(t.NamedTuple):
69+
"""Fixture for workspace root normalization cases."""
70+
71+
test_id: str
72+
config: dict[str, t.Any]
73+
expected_roots: list[str]
74+
75+
WORKSPACE_ROOT_FIXTURES: ClassVar[list[WorkspaceRootFixture]] = [
76+
WorkspaceRootFixture(
77+
test_id="tilde-mixed-trailing-slash",
78+
config={
79+
"~/study/c": {
80+
"cpython": {"repo": "git+https://github.com/python/cpython.git"},
81+
},
82+
"~/study/c/": {
83+
"tmux": {"repo": "git+https://github.com/tmux/tmux.git"},
84+
},
85+
},
86+
expected_roots=["~/study/c/"],
87+
),
88+
WorkspaceRootFixture(
89+
test_id="home-vs-absolute",
90+
config={
91+
str(pathlib.Path.home() / "study" / "c"): {
92+
"cpython": {"repo": "git+https://github.com/python/cpython.git"},
93+
},
94+
"~/study/c/": {
95+
"tmux": {"repo": "git+https://github.com/tmux/tmux.git"},
96+
},
97+
},
98+
expected_roots=["~/study/c/"],
99+
),
100+
WorkspaceRootFixture(
101+
test_id="relative-vs-tilde",
102+
config={
103+
"./study/c": {
104+
"cpython": {"repo": "git+https://github.com/python/cpython.git"},
105+
},
106+
"~/study/c/": {
107+
"tmux": {"repo": "git+https://github.com/tmux/tmux.git"},
108+
},
109+
},
110+
expected_roots=["~/study/c/"],
111+
),
112+
]
113+
114+
@pytest.mark.parametrize(
115+
list(WorkspaceRootFixture._fields),
116+
[
117+
pytest.param(
118+
*fixture,
119+
marks=pytest.mark.xfail(
120+
reason=(
121+
"Workspace root normalization not yet implemented in formatter."
122+
),
123+
strict=True,
124+
),
125+
)
126+
for fixture in WORKSPACE_ROOT_FIXTURES
127+
],
128+
ids=[fixture.test_id for fixture in WORKSPACE_ROOT_FIXTURES],
129+
)
130+
def test_workspace_root_normalization(
131+
self,
132+
test_id: str,
133+
config: dict[str, t.Any],
134+
expected_roots: list[str],
135+
) -> None:
136+
"""Ensure format_config merges duplicate workspace roots."""
137+
assert test_id # ensure fixture naming used for clarity
138+
formatted, _changes = format_config(config)
139+
assert list(formatted.keys()) == expected_roots
140+
68141
def test_sort_directories(self) -> None:
69142
"""Test that directories are sorted alphabetically."""
70143
config = {

0 commit comments

Comments
 (0)