Skip to content

Commit a81abb0

Browse files
committed
docs(config[save_config_yaml,save_config_json]) add doctests
why: Both functions lacked Examples sections despite the project requiring working doctests on all public functions. what: - Add Examples section to save_config_yaml with round-trip read check - Add Examples section to save_config_json with json.loads round-trip check
1 parent 9dfb37c commit a81abb0

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/vcspull/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,15 @@ def save_config_yaml(config_file_path: pathlib.Path, data: dict[t.Any, t.Any]) -
800800
Path to the configuration file to write
801801
data : dict
802802
Configuration data to save
803+
804+
Examples
805+
--------
806+
>>> import pathlib, tempfile
807+
>>> with tempfile.TemporaryDirectory() as tmp:
808+
... p = pathlib.Path(tmp) / "cfg.yaml"
809+
... save_config_yaml(p, {"~/code/": {"myrepo": "git+https://example.com/repo.git"}})
810+
... "myrepo" in p.read_text(encoding="utf-8")
811+
True
803812
"""
804813
yaml_content = ConfigReader._dump(
805814
fmt="yaml",
@@ -818,6 +827,16 @@ def save_config_json(config_file_path: pathlib.Path, data: dict[t.Any, t.Any]) -
818827
Path to the configuration file to write
819828
data : dict
820829
Configuration data to save
830+
831+
Examples
832+
--------
833+
>>> import json, pathlib, tempfile
834+
>>> with tempfile.TemporaryDirectory() as tmp:
835+
... p = pathlib.Path(tmp) / "cfg.json"
836+
... save_config_json(p, {"~/code/": {"myrepo": "git+https://example.com/repo.git"}})
837+
... loaded = json.loads(p.read_text(encoding="utf-8"))
838+
... "~/code/" in loaded
839+
True
821840
"""
822841
json_content = ConfigReader._dump(
823842
fmt="json",

0 commit comments

Comments
 (0)