Skip to content

Commit

Permalink
DiskStorage: preserve quotes in YAML (#36)
Browse files Browse the repository at this point in the history
Closes: #32
  • Loading branch information
kokorin authored Jul 9, 2024
1 parent 9f262d0 commit b75bc54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions dbt_pumpkin/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}
Expand Down
27 changes: 26 additions & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit b75bc54

Please sign in to comment.