From b8efc44eaec292b5d63a1a7f508ebbbba90f5817 Mon Sep 17 00:00:00 2001 From: Noortheen Raja Date: Sun, 17 Mar 2024 23:21:06 +0530 Subject: [PATCH] test: update tests for copier v9 --- pyproject.toml | 1 + tests/conftest.py | 7 ++++--- tests/data.py | 44 ++++++++++++++++++---------------------- tests/helpers.py | 10 +++------ tests/test_generation.py | 19 +++++++++++------ 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 356c264..bb455d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/tests/conftest.py b/tests/conftest.py index e7bab9c..fc3d265 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/data.py b/tests/data.py index e73ea9a..a0752be 100644 --- a/tests/data.py +++ b/tests/data.py @@ -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", } diff --git a/tests/helpers.py b/tests/helpers.py index 8b2e016..193e86a 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -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": @@ -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 \ No newline at end of file + return files diff --git a/tests/test_generation.py b/tests/test_generation.py index 012f536..c0f26e9 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -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"), + ] + )