Skip to content

Commit de1e1a2

Browse files
committed
tests(fixtures[dedent]): normalize multi-line YAML/JSON samples
why: Several fixtures still built config blobs from chained string literals, which are harder to tweak than a single dedented block. what: - use textwrap.dedent triple-quoted strings for duplicate-root YAML and JSON in test_config_reader - switch the vcspull add duplicate-root fixture to the same style and import textwrap alongside existing helpers
1 parent 9e18ea8 commit de1e1a2

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

tests/cli/test_add.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import argparse
66
import logging
77
import subprocess
8+
import textwrap
89
import typing as t
910

1011
import pytest
@@ -365,13 +366,15 @@ def test_add_repo_duplicate_merge_behavior(
365366

366367
config_file = tmp_path / ".vcspull.yaml"
367368
config_file.write_text(
368-
(
369-
"~/study/python/:\n"
370-
" repo1:\n"
371-
" repo: git+https://example.com/repo1.git\n"
372-
"~/study/python/:\n"
373-
" repo2:\n"
374-
" repo: git+https://example.com/repo2.git\n"
369+
textwrap.dedent(
370+
"""\
371+
~/study/python/:
372+
repo1:
373+
repo: git+https://example.com/repo1.git
374+
~/study/python/:
375+
repo2:
376+
repo: git+https://example.com/repo2.git
377+
"""
375378
),
376379
encoding="utf-8",
377380
)

tests/test_config_reader.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import pathlib
6+
import textwrap
67

78
from vcspull._internal.config_reader import DuplicateAwareConfigReader
89

@@ -15,13 +16,15 @@ def _write(tmp_path: pathlib.Path, name: str, content: str) -> pathlib.Path:
1516

1617
def test_duplicate_aware_reader_records_yaml_duplicates(tmp_path: pathlib.Path) -> None:
1718
"""YAML duplicate workspace roots are captured without data loss."""
18-
yaml_content = (
19-
"~/study/python/:\n"
20-
" repo1:\n"
21-
" repo: git+https://example.com/repo1.git\n"
22-
"~/study/python/:\n"
23-
" repo2:\n"
24-
" repo: git+https://example.com/repo2.git\n"
19+
yaml_content = textwrap.dedent(
20+
"""\
21+
~/study/python/:
22+
repo1:
23+
repo: git+https://example.com/repo1.git
24+
~/study/python/:
25+
repo2:
26+
repo: git+https://example.com/repo2.git
27+
"""
2528
)
2629
config_path = _write(tmp_path, "config.yaml", yaml_content)
2730

@@ -47,7 +50,13 @@ def test_duplicate_aware_reader_handles_yaml_without_duplicates(
4750
tmp_path: pathlib.Path,
4851
) -> None:
4952
"""YAML without duplicate keys reports an empty duplicate map."""
50-
yaml_content = "~/code/:\n repo:\n repo: git+https://example.com/repo.git\n"
53+
yaml_content = textwrap.dedent(
54+
"""\
55+
~/code/:
56+
repo:
57+
repo: git+https://example.com/repo.git
58+
"""
59+
)
5160
config_path = _write(tmp_path, "single.yaml", yaml_content)
5261

5362
reader = DuplicateAwareConfigReader.from_file(config_path)
@@ -62,12 +71,14 @@ def test_duplicate_aware_reader_handles_yaml_without_duplicates(
6271

6372
def test_duplicate_aware_reader_passes_through_json(tmp_path: pathlib.Path) -> None:
6473
"""JSON configs remain supported and duplicates remain empty."""
65-
json_content = (
66-
"{\n"
67-
' "~/code/": {\n'
68-
' "repo": {"repo": "git+https://example.com/repo.git"}\n'
69-
" }\n"
70-
"}\n"
74+
json_content = textwrap.dedent(
75+
"""\
76+
{
77+
"~/code/": {
78+
"repo": {"repo": "git+https://example.com/repo.git"}
79+
}
80+
}
81+
"""
7182
)
7283
config_path = _write(tmp_path, "config.json", json_content)
7384

0 commit comments

Comments
 (0)