Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
szvsw committed Sep 26, 2024
1 parent e878dfa commit c7b8d53
Showing 1 changed file with 73 additions and 22 deletions.
95 changes: 73 additions & 22 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -39,42 +42,62 @@ 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):
"""Test that the devcontainer files are not created when devcontainer=n"""
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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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):
Expand All @@ -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")

Expand All @@ -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")

0 comments on commit c7b8d53

Please sign in to comment.