Skip to content

Commit

Permalink
fix: ignore empty YAML documents in copier.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
sisp committed Feb 28, 2024
1 parent 2f72105 commit 14865bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion copier/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class _Loader(yaml.FullLoader):

with conf_path.open("rb") as f:
try:
flattened_result = lflatten(yaml.load_all(f, Loader=_Loader))
flattened_result = lflatten(filter(None, yaml.load_all(f, Loader=_Loader)))
except yaml.parser.ParserError as e:
raise InvalidConfigFileError(conf_path, quiet) from e

Expand Down
26 changes: 26 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ def test_valid_multi_section(tmp_path: Path) -> None:
}


def test_empty_section(tmp_path: Path) -> None:
"""Empty sections are ignored."""
build_file_tree(
{
(tmp_path / "copier.yml"): (
"""\
---
---
---
your_age:
type: int
your_name:
type: str
---
"""
),
}
)
template = Template(str(tmp_path))
assert template.questions_data == {
"your_age": {"type": "int"},
"your_name": {"type": "str"},
}


def test_config_data_empty() -> None:
template = Template("tests/demo_config_empty")
assert template.config_data == {}
Expand Down

0 comments on commit 14865bf

Please sign in to comment.