From c7b8d53ff1801fb049738aab65be381e6880a2ef Mon Sep 17 00:00:00 2001 From: Sam Wolk <36545842+szvsw@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:52:06 -0400 Subject: [PATCH] add some comments --- tests/test_cookiecutter.py | 95 +++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 22 deletions(-) diff --git a/tests/test_cookiecutter.py b/tests/test_cookiecutter.py index 26d074d..2bb2e66 100644 --- a/tests/test_cookiecutter.py +++ b/tests/test_cookiecutter.py @@ -29,7 +29,10 @@ def test_using_pytest(cookies, tmp_path): # Install the poetry environment and run the tests. with run_within_dir(str(result.project_path)): - assert subprocess.check_call(shlex.split("poetry install --no-interaction")) == 0 + assert ( + subprocess.check_call(shlex.split("poetry install --no-interaction")) + == 0 + ) assert subprocess.check_call(shlex.split("poetry run make test")) == 0 @@ -39,7 +42,9 @@ def test_devcontainer(cookies, tmp_path): result = cookies.bake(extra_context={"devcontainer": "y"}) assert result.exit_code == 0 assert os.path.isfile(f"{result.project_path}/.devcontainer/devcontainer.json") - assert os.path.isfile(f"{result.project_path}/.devcontainer/postCreateCommand.sh") + assert os.path.isfile( + f"{result.project_path}/.devcontainer/postCreateCommand.sh" + ) def test_not_devcontainer(cookies, tmp_path): @@ -47,34 +52,52 @@ def test_not_devcontainer(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"devcontainer": "n"}) assert result.exit_code == 0 - assert not os.path.isfile(f"{result.project_path}/.devcontainer/devcontainer.json") - assert not os.path.isfile(f"{result.project_path}/.devcontainer/postCreateCommand.sh") + assert not os.path.isfile( + f"{result.project_path}/.devcontainer/devcontainer.json" + ) + assert not os.path.isfile( + f"{result.project_path}/.devcontainer/postCreateCommand.sh" + ) def test_cicd_contains_artifactory_secrets(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"publish_to": "artifactory"}) assert result.exit_code == 0 - assert is_valid_yaml(result.project_path / ".github" / "workflows" / "on-release-main.yml") + assert is_valid_yaml( + result.project_path / ".github" / "workflows" / "on-release-main.yml" + ) for text in ["ARTIFACTORY_URL", "ARTIFACTORY_USERNAME", "ARTIFACTORY_PASSWORD"]: - assert file_contains_text(f"{result.project_path}/.github/workflows/on-release-main.yml", text) - assert file_contains_text(f"{result.project_path}/Makefile", "build-and-publish") + assert file_contains_text( + f"{result.project_path}/.github/workflows/on-release-main.yml", text + ) + assert file_contains_text( + f"{result.project_path}/Makefile", "build-and-publish" + ) def test_cicd_contains_pypi_secrets(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"publish_to": "pypi"}) assert result.exit_code == 0 - assert is_valid_yaml(result.project_path / ".github" / "workflows" / "on-release-main.yml") - assert file_contains_text(f"{result.project_path}/.github/workflows/on-release-main.yml", "PYPI_TOKEN") - assert file_contains_text(f"{result.project_path}/Makefile", "build-and-publish") + assert is_valid_yaml( + result.project_path / ".github" / "workflows" / "on-release-main.yml" + ) + assert file_contains_text( + f"{result.project_path}/.github/workflows/on-release-main.yml", "PYPI_TOKEN" + ) + assert file_contains_text( + f"{result.project_path}/Makefile", "build-and-publish" + ) def test_dont_publish(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"publish_to": "none"}) assert result.exit_code == 0 - assert is_valid_yaml(result.project_path / ".github" / "workflows" / "on-release-main.yml") + assert is_valid_yaml( + result.project_path / ".github" / "workflows" / "on-release-main.yml" + ) assert not file_contains_text( f"{result.project_path}/.github/workflows/on-release-main.yml", "make build-and-publish", @@ -86,7 +109,9 @@ def test_mkdocs(cookies, tmp_path): result = cookies.bake(extra_context={"mkdocs": "y"}) assert result.exit_code == 0 assert is_valid_yaml(result.project_path / ".github" / "workflows" / "main.yml") - assert is_valid_yaml(result.project_path / ".github" / "workflows" / "on-release-main.yml") + assert is_valid_yaml( + result.project_path / ".github" / "workflows" / "on-release-main.yml" + ) assert file_contains_text( f"{result.project_path}/.github/workflows/on-release-main.yml", "mkdocs gh-deploy", @@ -100,7 +125,9 @@ def test_not_mkdocs(cookies, tmp_path): result = cookies.bake(extra_context={"mkdocs": "n"}) assert result.exit_code == 0 assert is_valid_yaml(result.project_path / ".github" / "workflows" / "main.yml") - assert is_valid_yaml(result.project_path / ".github" / "workflows" / "on-release-main.yml") + assert is_valid_yaml( + result.project_path / ".github" / "workflows" / "on-release-main.yml" + ) assert not file_contains_text( f"{result.project_path}/.github/workflows/on-release-main.yml", "mkdocs gh-deploy", @@ -137,7 +164,9 @@ def test_codecov(cookies, tmp_path): assert result.exit_code == 0 assert is_valid_yaml(result.project_path / ".github" / "workflows" / "main.yml") assert os.path.isfile(f"{result.project_path}/codecov.yaml") - assert os.path.isfile(f"{result.project_path}/.github/workflows/validate-codecov-config.yml") + assert os.path.isfile( + f"{result.project_path}/.github/workflows/validate-codecov-config.yml" + ) def test_not_codecov(cookies, tmp_path): @@ -146,30 +175,43 @@ def test_not_codecov(cookies, tmp_path): assert result.exit_code == 0 assert is_valid_yaml(result.project_path / ".github" / "workflows" / "main.yml") assert not os.path.isfile(f"{result.project_path}/codecov.yaml") - assert not os.path.isfile(f"{result.project_path}/.github/workflows/validate-codecov-config.yml") + assert not os.path.isfile( + f"{result.project_path}/.github/workflows/validate-codecov-config.yml" + ) def test_remove_release_workflow(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"publish_to": "none", "mkdocs": "y"}) assert result.exit_code == 0 - assert os.path.isfile(f"{result.project_path}/.github/workflows/on-release-main.yml") + assert os.path.isfile( + f"{result.project_path}/.github/workflows/on-release-main.yml" + ) result = cookies.bake(extra_context={"publish_to": "none", "mkdocs": "n"}) assert result.exit_code == 0 - assert not os.path.isfile(f"{result.project_path}/.github/workflows/on-release-main.yml") + assert not os.path.isfile( + f"{result.project_path}/.github/workflows/on-release-main.yml" + ) def test_pyright(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"typechecking": "pyright"}) assert result.exit_code == 0 - assert file_contains_text(f"{result.project_path}/pyproject.toml", "[tool.pyright]") + # check the toml file + assert file_contains_text( + f"{result.project_path}/pyproject.toml", "[tool.pyright]" + ) assert file_contains_text(f"{result.project_path}/pyproject.toml", "pyright =") - assert not file_contains_text(f"{result.project_path}/pyproject.toml", "[tool.mypy]") + assert not file_contains_text( + f"{result.project_path}/pyproject.toml", "[tool.mypy]" + ) assert not file_contains_text(f"{result.project_path}/pyproject.toml", "mypy =") + # check the make file assert file_contains_text(f"{result.project_path}/Makefile", "pyright") assert not file_contains_text(f"{result.project_path}/Makefile", "mypy") + # check the tox file assert file_contains_text(f"{result.project_path}/tox.ini", "pyright") assert not file_contains_text(f"{result.project_path}/tox.ini", "mypy") @@ -178,11 +220,20 @@ def test_mypy(cookies, tmp_path): with run_within_dir(tmp_path): result = cookies.bake(extra_context={"typechecking": "mypy"}) assert result.exit_code == 0 - assert file_contains_text(f"{result.project_path}/pyproject.toml", "[tool.mypy]") + # check the toml file + assert file_contains_text( + f"{result.project_path}/pyproject.toml", "[tool.mypy]" + ) assert file_contains_text(f"{result.project_path}/pyproject.toml", "mypy =") - assert not file_contains_text(f"{result.project_path}/pyproject.toml", "[tool.pyright]") - assert not file_contains_text(f"{result.project_path}/pyproject.toml", "pyright =") + assert not file_contains_text( + f"{result.project_path}/pyproject.toml", "[tool.pyright]" + ) + assert not file_contains_text( + f"{result.project_path}/pyproject.toml", "pyright =" + ) + # check the make file assert file_contains_text(f"{result.project_path}/Makefile", "mypy") assert not file_contains_text(f"{result.project_path}/Makefile", "pyright") + # check the tox file assert file_contains_text(f"{result.project_path}/tox.ini", "mypy") assert not file_contains_text(f"{result.project_path}/tox.ini", "pyright")