copier/tests/test_exclude.py
Jairo Llopis 0441b86f0c
Refactor (#314)
* Refactor
* Fix #110.
* Rewrite test_config_exclude, test_config_exclude_overridden and test_config_include. These tests were badly designed, using a monkeypatch that would never happen in the real world, and actually producing false positives. I moved them to test_exclude.py and rewritten to test the what and not the how.
* Fix #214 by removing skip option. Relevant tests use the better skip_if_exists=["**"].
* Remove subdirectory flag from API/CLI. It was confusing and could lead to bad maintenance situations. Fixes #315.
* Remove extra_paths and fix #321
* Remember that you cannot use _copier_conf.src_path as a path now
* use dataclasses
* Create errors module, simplify some tests, fix many others
* Fix some tests, complete EnvOps removal
* Fix #214 and some tests related to it
* Reorder code
* Update docs and imports
* Modularize test_complex_questions
* Interlink worker and questionary a bit better
* Removal of Questionary class, which only had 1 meaningful method that is now merged into Worker to avoid circular dependencies.
* Fix #280 in a simple way: only user answers are type-casted inside API, and CLI transforms all `--data` using YAML always. Predictable.
* Use prereleases correctly.
* Reorder AnswersMap to have a more significative repr.
* Simpler cache for old `Question.get_choices()` method (renamed now).
* fix wrong test
* Fix test_subdirectory
* Fix test_tasks (and remove tests/demo_tasks)
* Fix path filter tests, and move it to test_exclude, where it belongs
* Make test_config pass
* Fix more wrongly designed tests
* Use cached_property backport if needed
* xfail test known to fail on mac
* force posix paths on windows
* Add typing_extensions for python < 3.8
* Sort dependencies in pyproject.toml
* Support python 3.6 str-to-datetime conversion
* Workaround https://bugs.python.org/issue43095
* xfail test_path_filter on windows
* Upgrade mkdocs and other dependencies to fix https://github.com/pawamoy/mkdocstrings/issues/222
* Add missing reference docs.
* Add workaround for https://github.com/pawamoy/mkdocstrings/pull/209
* Docs.
* Remove validators module
* Add workaround for https://github.com/pawamoy/mkdocstrings/issues/225
* Restore docs autorefs as explained in https://github.com/pawamoy/mkdocstrings/issues/226#issuecomment-775413562.
* Workaround https://github.com/pawamoy/pytkdocs/issues/86
2021-02-09 18:22:47 +00:00

94 lines
3.0 KiB
Python

import platform
from pathlib import Path
import pytest
from copier.main import run_auto
from .helpers import PROJECT_TEMPLATE, build_file_tree
def test_exclude_recursive(tmp_path):
"""Copy is done properly when excluding recursively."""
src = f"{PROJECT_TEMPLATE}_exclude"
run_auto(src, tmp_path)
assert not (tmp_path / "bad").exists()
assert not (tmp_path / "bad").is_dir()
def test_exclude_recursive_negate(tmp_path):
"""Copy is done properly when copy_me.txt is the sole file copied."""
src = f"{PROJECT_TEMPLATE}_exclude_negate"
run_auto(src, tmp_path)
assert (tmp_path / "copy_me.txt").exists()
assert (tmp_path / "copy_me.txt").is_file()
assert not (tmp_path / "do_not_copy_me.txt").exists()
def test_config_exclude(tmp_path):
src, dst = tmp_path / "src", tmp_path / "dst"
build_file_tree({src / "copier.yml": "_exclude: ['*.txt']", src / "aaaa.txt": ""})
run_auto(str(src), dst, quiet=True)
assert not (dst / "aaaa.txt").exists()
assert (dst / "copier.yml").exists()
def test_config_exclude_extended(tmp_path):
src, dst = tmp_path / "src", tmp_path / "dst"
build_file_tree({src / "copier.yml": "_exclude: ['*.txt']", src / "aaaa.txt": ""})
run_auto(str(src), dst, quiet=True, exclude=["*.yml"])
assert not (dst / "aaaa.txt").exists()
assert not (dst / "copier.yml").exists()
def test_config_include(tmp_path):
src, dst = tmp_path / "src", tmp_path / "dst"
build_file_tree(
{src / "copier.yml": "_exclude: ['!.svn']", src / ".svn" / "hello": ""}
)
run_auto(str(src), dst, quiet=True)
assert (dst / ".svn" / "hello").exists()
assert (dst / "copier.yml").exists()
@pytest.mark.xfail(
condition=platform.system() in {"Darwin", "Windows"},
reason="OS without proper UTF-8 filesystem.",
strict=True,
)
def test_path_filter(tmp_path_factory):
src, dst = tmp_path_factory.mktemp("src"), tmp_path_factory.mktemp("dst")
file_excluded = {
"x.exclude": True,
"do_not.exclude!": False,
# dir patterns and their negations
Path("exclude_dir", "x"): True,
Path("exclude_dir", "please_copy_me"): False, # no mercy
Path("not_exclude_dir", "x!"): False,
# unicode patterns
"mañana.txt": True,
"mañana.txt": False,
"manana.txt": False,
}
file_tree_spec = {
src
/ "copier.yaml": """
_exclude:
# 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"
""",
}
for key, value in file_excluded.items():
file_tree_spec[src / key] = str(value)
build_file_tree(file_tree_spec)
run_auto(str(src), dst)
for key, value in file_excluded.items():
assert (dst / key).exists() != value