Skip to content

Commit 95f0bb4

Browse files
committed
docs(add[_save_ordered_items]) Add doctest covering YAML and JSON paths
why: Function lacked doctests, violating project requirement that all functions have working doctests. what: - Add doctest exercising YAML output path - Add doctest exercising JSON output path - Use tmp_path from doctest_namespace for file I/O Fixes #526
1 parent afe4297 commit 95f0bb4

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/vcspull/cli/add.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,35 @@ def _save_ordered_items(
311311
config_file_path: pathlib.Path,
312312
ordered_items: list[dict[str, t.Any]],
313313
) -> None:
314-
"""Persist ordered items in the format matching the config file extension."""
314+
"""Persist ordered items in the format matching the config file extension.
315+
316+
Parameters
317+
----------
318+
config_file_path : pathlib.Path
319+
Path to config file (.yaml or .json).
320+
ordered_items : list of dict
321+
Each dict has ``"label"`` and ``"section"`` keys.
322+
323+
Examples
324+
--------
325+
YAML output:
326+
327+
>>> import pathlib
328+
>>> config_file = tmp_path / "test.yaml"
329+
>>> items = [{"label": "~/code/", "section": {"myrepo": "git+https://example.com/r.git"}}]
330+
>>> _save_ordered_items(config_file, items)
331+
>>> config_file.read_text().strip() # doctest: +ELLIPSIS
332+
'~/code/...'
333+
334+
JSON output:
335+
336+
>>> config_file = tmp_path / "test.json"
337+
>>> _save_ordered_items(config_file, items)
338+
>>> import json
339+
>>> data = json.loads(config_file.read_text())
340+
>>> "~/code/" in data
341+
True
342+
"""
315343
if config_file_path.suffix.lower() == ".json":
316344
save_config_json(
317345
config_file_path,

0 commit comments

Comments
 (0)