mirror of
https://github.com/copier-org/copier.git
synced 2025-05-05 15:32:54 +00:00
This new command allows to reapply a template, keeping old answers but discarding subproject evolution. It is useful when there are bugs replaying an old version of the template, or when the subproject has drifted too much from the template and you need to reset it. BREAKING CHANGE: All CLI calls to Copier must now include the subcommand as the 1st argument. For example, `copier` must become now `copier update`; also `copier ./tpl ./dst` must become `copier copy ./tpl ./dst`. BREAKING CHANGE: All flags must go after the subcommand now. For example, `copier -r HEAD update ./dst` must now become `copier update -r HEAD ./dst` or `copier update ./dst -r HEAD`. BREAKING CHANGE: Automatic mode removed. Since now subcommands are required, the automatic mode is removed. BREAKING CHANGE: Deprecated `copier.copy` function is removed. Use `copier.run_copy`, `copier.run_update` or `copier.run_recopy` explicitly as needed. Fix https://github.com/copier-org/copier/issues/1081 Close https://github.com/copier-org/copier/issues/1082
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
import warnings
|
|
|
|
import pytest
|
|
|
|
import copier
|
|
|
|
from .helpers import build_file_tree
|
|
|
|
|
|
def test_normal_jinja2(tmp_path_factory: pytest.TempPathFactory) -> None:
|
|
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
|
|
build_file_tree(
|
|
{
|
|
(src / "copier.yml"): (
|
|
"""\
|
|
_templates_suffix: .jinja
|
|
_envops:
|
|
autoescape: false
|
|
variable_start_string: "{{"
|
|
variable_end_string: "}}"
|
|
block_start_string: "{%"
|
|
block_end_string: "%}"
|
|
comment_start_string: "{#"
|
|
comment_end_string: "#}"
|
|
lstrip_blocks: true
|
|
trim_blocks: true
|
|
name: Guybrush
|
|
todo: Become a pirate
|
|
"""
|
|
),
|
|
(src / "TODO.txt.jinja"): (
|
|
"""\
|
|
[[ {{ name }} TODO LIST]]
|
|
{# Let's put an ugly not-comment below #}
|
|
[# GROG #]
|
|
{% if name == 'Guybrush' %}
|
|
- {{ todo }}
|
|
{% endif %}
|
|
"""
|
|
),
|
|
}
|
|
)
|
|
# No warnings, because template is explicit
|
|
with warnings.catch_warnings():
|
|
warnings.simplefilter("error")
|
|
copier.run_copy(str(src), dst, defaults=True, overwrite=True)
|
|
todo = (dst / "TODO.txt").read_text()
|
|
expected = "[[ Guybrush TODO LIST]]\n[# GROG #]\n - Become a pirate\n"
|
|
assert todo == expected
|
|
|
|
|
|
def test_to_not_keep_trailing_newlines_in_jinja2(
|
|
tmp_path_factory: pytest.TempPathFactory,
|
|
) -> None:
|
|
src, dst = map(tmp_path_factory.mktemp, ("src", "dst"))
|
|
build_file_tree(
|
|
{
|
|
(src / "copier.yml"): (
|
|
"""\
|
|
_templates_suffix: .jinja
|
|
_envops:
|
|
keep_trailing_newline: false
|
|
data: foo
|
|
"""
|
|
),
|
|
(src / "data.txt.jinja"): "This is {{ data }}.\n",
|
|
}
|
|
)
|
|
# No warnings, because template is explicit
|
|
with warnings.catch_warnings():
|
|
warnings.simplefilter("error")
|
|
copier.run_copy(str(src), dst, defaults=True, overwrite=True)
|
|
assert (dst / "data.txt").read_text() == "This is foo."
|