|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import logging |
| 6 | +import pathlib |
6 | 7 | import typing as t |
7 | 8 |
|
8 | 9 | import pytest |
|
11 | 12 | from vcspull.cli.fmt import format_config, format_config_file, normalize_repo_config |
12 | 13 |
|
13 | 14 | if t.TYPE_CHECKING: |
14 | | - import pathlib |
15 | | - |
16 | 15 | from _pytest.logging import LogCaptureFixture |
17 | 16 |
|
18 | 17 |
|
@@ -65,6 +64,60 @@ def test_both_url_and_repo(self) -> None: |
65 | 64 | class TestFormatConfig: |
66 | 65 | """Test configuration formatting.""" |
67 | 66 |
|
| 67 | + @pytest.mark.xfail( |
| 68 | + reason="Workspace root normalization not yet implemented in formatter.", |
| 69 | + strict=True, |
| 70 | + ) |
| 71 | + @pytest.mark.parametrize( |
| 72 | + "config, expected_roots", |
| 73 | + [ |
| 74 | + pytest.param( |
| 75 | + { |
| 76 | + "~/study/c": { |
| 77 | + "cpython": {"repo": "git+https://github.com/python/cpython.git"}, |
| 78 | + }, |
| 79 | + "~/study/c/": { |
| 80 | + "tmux": {"repo": "git+https://github.com/tmux/tmux.git"}, |
| 81 | + }, |
| 82 | + }, |
| 83 | + ["~/study/c/"], |
| 84 | + id="tilde-mixed-trailing-slash", |
| 85 | + ), |
| 86 | + pytest.param( |
| 87 | + { |
| 88 | + str(pathlib.Path.home() / "study" / "c"): { |
| 89 | + "cpython": {"repo": "git+https://github.com/python/cpython.git"}, |
| 90 | + }, |
| 91 | + "~/study/c/": { |
| 92 | + "tmux": {"repo": "git+https://github.com/tmux/tmux.git"}, |
| 93 | + }, |
| 94 | + }, |
| 95 | + ["~/study/c/"], |
| 96 | + id="home-vs-absolute", |
| 97 | + ), |
| 98 | + pytest.param( |
| 99 | + { |
| 100 | + "./study/c": { |
| 101 | + "cpython": {"repo": "git+https://github.com/python/cpython.git"}, |
| 102 | + }, |
| 103 | + "~/study/c/": { |
| 104 | + "tmux": {"repo": "git+https://github.com/tmux/tmux.git"}, |
| 105 | + }, |
| 106 | + }, |
| 107 | + ["~/study/c/"], |
| 108 | + id="relative-vs-tilde", |
| 109 | + ), |
| 110 | + ], |
| 111 | + ) |
| 112 | + def test_workspace_root_normalization( |
| 113 | + self, |
| 114 | + config: dict[str, t.Any], |
| 115 | + expected_roots: list[str], |
| 116 | + ) -> None: |
| 117 | + """Ensure format_config merges duplicate workspace roots.""" |
| 118 | + formatted, _changes = format_config(config) |
| 119 | + assert list(formatted.keys()) == expected_roots |
| 120 | + |
68 | 121 | def test_sort_directories(self) -> None: |
69 | 122 | """Test that directories are sorted alphabetically.""" |
70 | 123 | config = { |
|
0 commit comments