Skip to content

Commit

Permalink
test: update tests for copier v9
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Mar 17, 2024
1 parent d963ad5 commit b8efc44
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dev = [
"validate-pyproject[all]<1.0.0,>=0.7.2",
"tomli<3.0.0,>=2.0.1",
"xonsh>=0.12.5",
"pyyaml>=6.0.1"
]

[tool.pytest.ini_options]
Expand Down
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ def bake(**ctx):
data.update(ctx)
template = Path(__file__).parent.parent
assert template.exists(), "Not the root path"
return copier.copy(
str(template),
return copier.run_copy(
src_path=str(template),
dst_path=tmpdir,
vcs_ref="HEAD",
data=data,
defaults=True
defaults=True,
unsafe=True,
)

return bake
44 changes: 20 additions & 24 deletions tests/data.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
COMMON_FILES = {
'.copier-answers.yml',
'.editorconfig',
'.gitattributes',
'.github/issue_template.md',
'.github/pull_request_template.md',
'.github/release-drafter.yml',
'.github/workflows/release.yml',
'.github/workflows/release-drafter.yml',
'.github/workflows/test.yml',
'.gitignore',
'.pre-commit-config.yaml',
'LICENSE',
'README.md',
'pyproject.toml',
'tests/__init__.py',
'tests/test_xontrib.py',
".copier-answers.yml",
".editorconfig",
".gitattributes",
".github/issue_template.md",
".github/FUNDING.yml",
".github/pull_request_template.md",
".github/release-drafter.yml",
".github/workflows/release.yml",
".github/workflows/release-drafter.yml",
".github/workflows/test.yml",
".gitignore",
".pre-commit-config.yaml",
"LICENSE",
"README.md",
"pyproject.toml",
"tests/__init__.py",
"tests/test_xontrib.py",
}

AUTO_LOADED = {
'xontrib_my_prompt/main.py',
'xontrib_my_prompt/__init__.py'
}
OLD_STYLE = {
'xontrib/my_prompt.py'
}
AUTO_LOADED = {"xontrib_my_prompt/main.py", "xontrib_my_prompt/__init__.py"}
OLD_STYLE = {"xontrib/my_prompt.py"}

SETUP_TOOLS_ONLY = {
'setup.py',
"setup.py",
}
10 changes: 3 additions & 7 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
from . import data


def get_all_files(path: "Path | str", root: Path = None):
if isinstance(path, str):
path = Path(path)
def get_all_files(path: Path, root: Path = None):
if root is None:
childs = list(path.iterdir())
assert len(childs) == 1
root = childs[0]
root = path
for p in path.iterdir():
if p.is_file():
if p.name == "pyproject.toml":
Expand Down Expand Up @@ -45,4 +41,4 @@ def get_expected_files(package_manager: str, autoloading: bool):
if package_manager == "setuptools":
files.update(data.SETUP_TOOLS_ONLY)

return files
return files
19 changes: 13 additions & 6 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
from .helpers import get_all_files, get_expected_files
import subprocess as sp


@pytest.mark.parametrize("autoloading", [False, True])
@pytest.mark.parametrize("builder", [
"setuptools", "poetry"
])
@pytest.mark.parametrize("builder", ["setuptools", "poetry"])
def test_it_generates(bake_cookie, builder, autoloading):
out = bake_cookie(package_manager=builder, enable_autoloading=autoloading)
expected = get_expected_files(builder, autoloading)
files = set(get_all_files(out.dst_path, ))
pkg = "xontrib-my-prompt"
files = set(get_all_files(out.dst_path / pkg))
assert files == expected

pip = [sys.executable, "-m", "pip"]
pkg = "xontrib-my-prompt"
# check it is installable with pip
sp.check_call([*pip, "install", os.path.join(out.dst_path, pkg), "-t", os.path.join(out.dst_path, "installed")])
sp.check_call(
[
*pip,
"install",
os.path.join(out.dst_path, pkg),
"-t",
os.path.join(out.dst_path, "installed"),
]
)

0 comments on commit b8efc44

Please sign in to comment.