Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
szvsw committed Sep 26, 2024
1 parent c7b8d53 commit 8755305
Showing 1 changed file with 22 additions and 67 deletions.
89 changes: 22 additions & 67 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ 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 @@ -42,62 +39,42 @@ 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 @@ -109,9 +86,7 @@ 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 @@ -125,9 +100,7 @@ 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 @@ -164,9 +137,7 @@ 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 @@ -175,38 +146,28 @@ 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
# 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", "[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")
Expand All @@ -221,16 +182,10 @@ def test_mypy(cookies, tmp_path):
result = cookies.bake(extra_context={"typechecking": "mypy"})
assert result.exit_code == 0
# 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", "[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")
Expand Down

0 comments on commit 8755305

Please sign in to comment.