copier/tests/test_tools.py
2020-02-26 20:13:45 +01:00

58 lines
1.5 KiB
Python

from pathlib import Path
import pytest
from copier import tools
from copier.config.factory import ConfigData, EnvOps
from .helpers import DATA, PROJECT_TEMPLATE
def test_render(dst):
envops = EnvOps().dict()
render = tools.Renderer(
ConfigData(src_path=PROJECT_TEMPLATE, dst_path=dst, data=DATA, envops=envops)
)
assert render.string("/hello/[[ what ]]/") == "/hello/world/"
assert render.string("/hello/world/") == "/hello/world/"
sourcepath = PROJECT_TEMPLATE / "pyproject.toml.tmpl"
result = render(sourcepath)
expected = Path("./tests/reference_files/pyproject.toml").read_text()
assert result == expected
TEST_PATTERNS = (
# simple file patterns and their negations
"*.exclude",
"!do_not.exclude",
# dir patterns and their negations
"exclude_dir/",
"!exclude_dir/please_copy_me",
"!not_exclude_dir/x",
# unicode patterns
"mañana.txt",
)
path_filter = tools.create_path_filter(TEST_PATTERNS)
@pytest.mark.parametrize(
"pattern,should_match",
(
# simple file patterns and their negations
("x.exclude", True),
("do_not.exclude!", False),
# dir patterns and their negations
("exclude_dir/x", True),
("exclude_dir/please_copy_me", False), # no mercy
("not_exclude_dir/x!", False),
# unicode patterns
("mañana.txt", True),
("mañana.txt", False),
("manana.txt", False),
),
)
def test_create_path_filter(pattern, should_match):
assert path_filter(pattern) == should_match