diff --git a/dbt_pumpkin/storage.py b/dbt_pumpkin/storage.py index 765ce43..19abde5 100644 --- a/dbt_pumpkin/storage.py +++ b/dbt_pumpkin/storage.py @@ -23,6 +23,7 @@ def __init__(self, root_dir: Path, *, read_only: bool): self._root_dir = root_dir self._read_only = read_only self._yaml = YAML(typ="rt") + self._yaml.preserve_quotes = True def load_yaml(self, files: set[Path]) -> dict[Path, Any]: result: dict[Path, Any] = {} diff --git a/tests/test_storage.py b/tests/test_storage.py index c558009..1e9d0dc 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -37,7 +37,7 @@ def test_save_yaml_read_only(tmp_path: Path): assert not (tmp_path / "schema.yml").exists() -def test_roundtrip(tmp_path: Path): +def test_roundtrip_preserve_comments(tmp_path: Path): content = textwrap.dedent("""\ version: 2 models: @@ -78,3 +78,28 @@ def test_roundtrip(tmp_path: Path): expected = content assert expected == actual + + +def test_roundtrip_preserve_quotes(tmp_path: Path): + content = textwrap.dedent("""\ + version: 2 + models: + - name: "my_model" + description: "my very first model" + columns: + - name: "id" + data_type: short + """) + + (tmp_path / "my_model.yml").write_text(content) + + storage = DiskStorage(tmp_path, read_only=False) + files = storage.load_yaml({Path("my_model.yml")}) + + yaml = files[Path("my_model.yml")] + assert len([m for m in yaml["models"] if m["name"] == "my_model"]) == 1 + storage.save_yaml(files) + + actual = (tmp_path / "my_model.yml").read_text() + + assert content == actual