copier/tests/test_empty_suffix.py
Jairo Llopis 6996b9cc7a feat: add recopy command and function
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
2023-05-17 11:56:13 +01:00

62 lines
1.8 KiB
Python

import pytest
import copier
from .helpers import build_file_tree
def test_empty_suffix(tmp_path_factory: pytest.TempPathFactory) -> None:
root, dest = map(tmp_path_factory.mktemp, ("src", "dst"))
build_file_tree(
{
(root / "copier.yaml"): (
"""\
_templates_suffix: ""
name:
type: str
default: pingu
"""
),
(root / "render_me"): "Hello {{name}}!",
(root / "{{name}}.txt"): "Hello {{name}}!",
(root / "{{name}}" / "render_me.txt"): "Hello {{name}}!",
}
)
copier.run_copy(str(root), dest, defaults=True, overwrite=True)
assert not (dest / "copier.yaml").exists()
assert (dest / "render_me").exists()
assert (dest / "pingu.txt").exists()
assert (dest / "pingu" / "render_me.txt").exists()
expected = "Hello pingu!"
assert (dest / "render_me").read_text() == expected
assert (dest / "pingu.txt").read_text() == expected
assert (dest / "pingu" / "render_me.txt").read_text() == expected
def test_binary_file_fallback_to_copy(tmp_path_factory: pytest.TempPathFactory) -> None:
root, dest = map(tmp_path_factory.mktemp, ("src", "dst"))
build_file_tree(
{
(root / "copier.yaml"): (
"""\
_templates_suffix: ""
name:
type: str
default: pingu
"""
),
(root / "logo.png"): (
b"\x89PNG\r\n\x1a\n\x00\rIHDR\x00\xec\n{{name}}\n\x00\xec"
),
}
)
copier.run_copy(str(root), dest, defaults=True, overwrite=True)
logo = dest / "logo.png"
assert logo.exists()
logo_bytes = logo.read_bytes()
assert b"{{name}}" in logo_bytes
assert b"pingu" not in logo_bytes