|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import logging |
| 6 | +import pathlib |
6 | 7 | import typing as t |
| 8 | +from typing import ClassVar |
7 | 9 |
|
8 | 10 | import pytest |
9 | 11 | import yaml |
10 | 12 |
|
11 | 13 | from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config |
12 | 14 |
|
13 | 15 | if t.TYPE_CHECKING: |
14 | | - import pathlib |
15 | | - |
16 | 16 | from _pytest.logging import LogCaptureFixture |
17 | 17 |
|
18 | 18 |
|
@@ -65,6 +65,79 @@ def test_both_url_and_repo(self) -> None: |
65 | 65 | class TestFormatConfig: |
66 | 66 | """Test configuration formatting.""" |
67 | 67 |
|
| 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 | + |
68 | 141 | def test_sort_directories(self) -> None: |
69 | 142 | """Test that directories are sorted alphabetically.""" |
70 | 143 | config = { |
|
0 commit comments