Skip to content

Commit 9bf0358

Browse files
committed
test(helpers) Add save_config_yaml()
1 parent dbf0cb7 commit 9bf0358

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import typing as t
77

8+
import yaml
89
from typing_extensions import Self
910

1011
from vcspull._internal.config_reader import ConfigReader
@@ -61,3 +62,14 @@ def write_config(config_path: pathlib.Path, content: str) -> pathlib.Path:
6162
def load_raw(data: str, fmt: t.Literal["yaml", "json"]) -> dict[str, t.Any]:
6263
"""Load configuration data via string value. Accepts yaml or json."""
6364
return ConfigReader._load(fmt=fmt, content=data)
65+
66+
67+
def save_config_yaml(config_file_path: pathlib.Path, data: dict[t.Any, t.Any]) -> None:
68+
"""Save a dictionary to a YAML file by utilizing write_config.
69+
70+
The primary difference from `write_config` is that this function
71+
accepts a dictionary and handles YAML serialization before calling
72+
`write_config`.
73+
"""
74+
yaml_content: str = yaml.dump(data)
75+
write_config(config_file_path, yaml_content)

0 commit comments

Comments
 (0)