8000 Add conditionally rendered project badges to template README.md by smkent · Pull Request #16 · smkent/cookie-python · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add conditionally rendered project badges to template README.md #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations 10000
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Cookiecutter][cookiecutter] template for new Python projects

[![coookie-python][logo]](#)
[![cookie-python][logo]](#)

A template for new Python projects, with:

Expand Down Expand Up @@ -28,6 +28,8 @@ Prerequisites: [Poetry][poetry]
* Setup: `poetry install`
* Test template rendering and run rendered project tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`
* Update test expected output files from test results:
`poetry run poe updatetests`

[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[logo]: https://raw.github.com/smkent/cookie-python/master/img/cookie-python.png
Expand Down
7 changes: 4 additions & 3 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"author_name": "",
"author_email": "",
"project_name": "",
"project_slug": "{{ cookiecutter.project_name|lower|replace('-', '_') }}",
"project_description": "",
Expand All @@ -13,5 +11,8 @@
"MIT"
],
"enable_coverage": "yes",
"enable_pypi_publish": "no"
"enable_pypi_publish": "no",
"author_name": "",
"author_email": "",
"github_user": ""
}
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ flake8 = { cmd = "flake8" }
mypy = { cmd = "mypy" }
pytest = { cmd = "pytest" }

updatetests = { cmd = "pytest --update-expected-outputs" }

[tool.isort]
atomic = true
profile = "black"
Expand Down
18 changes: 18 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest


def pytest_addoption(parser: pytest.Parser) -> None:
group = parser.getgroup("cookie", "python-cookie test helpers")
group.addoption(
"--update-expected-outputs",
action="store_true",
dest="update_expected_outputs",
help="Update expected test data with generated results",
)


@pytest.fixture
def opt_update_expected_outputs(request: pytest.FixtureRequest) -> bool:
value = request.config.getoption("--update-expected-outputs")
assert isinstance(value, bool)
return value
23 changes: 23 additions & 0 deletions tests/data/readme-github_user_only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

[![Build](https://img.shields.io/github/checks-status/ness/test-baked-cookie/master?label=build)][gh-actions]
[![GitHub stars](https://img.shields.io/github/stars/ness/test-baked-cookie?style=social)][repo]

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[gh-actions]: https://github.com/ness/test-baked-cookie/actions?query=branch%3Amaster
[poetry]: https://python-poetry.org/docs/#installation
[repo]: https://github.com/ness/test-baked-cookie
25 changes: 25 additions & 0 deletions tests/data/readme-github_user_with_coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

[![Build](https://img.shields.io/github/checks-status/ness/test-baked-cookie/master?label=build)][gh-actions]
[![codecov](https://codecov.io/gh/ness/test-baked-cookie/branch/master/graph/badge.svg)][codecov]
[![GitHub stars](https://img.shields.io/github/stars/ness/test-baked-cookie?style=social)][repo]

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[codecov]: https://codecov.io/gh/ness/test-baked-cookie
[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[gh-actions]: https://github.com/ness/test-baked-cookie/actions?query=branch%3Amaster
[poetry]: https://python-poetry.org/docs/#installation
[repo]: https://github.com/ness/test-baked-cookie
28 changes: 28 additions & 0 deletions tests/data/readme-github_user_with_coverage_and_pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

[![PyPI](https://img.shields.io/pypi/v/test-baked-cookie)][pypi]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/test-baked-cookie)][pypi]
[![Build](https://img.shields.io/github/checks-status/ness/test-baked-cookie/master?label=build)][gh-actions]
[![codecov](https://codecov.io/gh/ness/test-baked-cookie/branch/master/graph/badge.svg)][codecov]
[![GitHub stars](https://img.shields.io/github/stars/ness/test-baked-cookie?style=social)][repo]

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[codecov]: https://codecov.io/gh/ness/test-baked-cookie
[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[gh-actions]: https://github.com/ness/test-baked-cookie/actions?query=branch%3Amaster
[poetry]: https://python-poetry.org/docs/#installation
[pypi]: https://pypi.org/project/test-baked-cookie/
[repo]: https://github.com/ness/test-baked-cookie
26 changes: 26 additions & 0 deletions tests/data/readme-github_user_with_pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

[![PyPI](https://img.shields.io/pypi/v/test-baked-cookie)][pypi]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/test-baked-cookie)][pypi]
[![Build](https://img.shields.io/github/checks-status/ness/test-baked-cookie/master?label=build)][gh-actions]
[![GitHub stars](https://img.shields.io/github/stars/ness/test-baked-cookie?style=social)][repo]

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[gh-actions]: https://github.com/ness/test-baked-cookie/actions?query=branch%3Amaster
[poetry]: https://python-poetry.org/docs/#installation
[pypi]: https://pypi.org/project/test-baked-cookie/
[repo]: https://github.com/ness/test-baked-cookie
18 changes: 18 additions & 0 deletions tests/data/readme-no_github_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[poetry]: https://python-poetry.org/docs/#installation
18 changes: 18 additions & 0 deletions tests/data/readme-no_github_user_coverage_enabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[poetry]: https://python-poetry.org/docs/#installation
22 changes: 22 additions & 0 deletions tests/data/readme-no_github_user_pypi_enabled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# test-baked-cookie: This is a test project called "test-baked-cookie"

[![PyPI](https://img.shields.io/pypi/v/test-baked-cookie)][pypi]
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/test-baked-cookie)][pypi]

## Development

Prerequisites: [Poetry][poetry]

* Setup: `poetry install`
* Run all tests: `poetry run poe test`
* Fix linting errors: `poetry run poe lint`

---

Created from [smkent/cookie-python][cookie-python] using
[cookiecutter][cookiecutter]

[cookie-python]: https://github.com/smkent/cookie-python
[cookiecutter]: https://github.com/cookiecutter/cookiecutter
[poetry]: https://python-poetry.org/docs/#installation
[pypi]: https://pypi.org/project/test-baked-cookie/
95 changes: 95 additions & 0 deletions tests/readme_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from dataclasses import dataclass
from typing import Any, Iterable, List


@dataclass
class ParametrizeParams:
argnames: Iterable[str]
argvalues: Iterable[Any]
ids: Iterable[str]


@dataclass
class ReadmeCase:
id: str
argvalues: Iterable[str]


@dataclass
class ReadmeCaseParams:
id: str
github_user: str
enable_coverage: bool
enable_pypi_publish: bool


class ReadmeCases:
@classmethod
def all_cases(
cls,
) -> ParametrizeParams:
argnames = [
"github_user",
"enable_coverage",
"enable_pypi_publish",
"expected_content_file",
]
ids: List[str] = []
argvalues: List[Any] = []
for case in [
ReadmeCaseParams(
id="no_github_user",
github_user="",
enable_coverage=False,
enable_pypi_publish=False,
),
ReadmeCaseParams(
id="no_github_user_coverage_enabled",
github_user="",
enable_coverage=True,
enable_pypi_publish=False,
),
ReadmeCaseParams(
id="no_github_user_pypi_enabled",
github_user="",
enable_coverage=False,
enable_pypi_publish=True,
),
ReadmeCaseParams(
id="github_user_only",
github_user="ness",
enable_coverage=False,
enable_pypi_publish=False,
),
ReadmeCaseParams(
id="github_user_with_coverage",
github_user="ness",
enable_coverage=True,
enable_pypi_publish=False,
),
ReadmeCaseParams(
id="github_user_with_pypi",
github_user="ness",
enable_coverage=False,
enable_pypi_publish=True,
),
ReadmeCaseParams(
id="github_user_with_coverage_and_pypi",
github_user="ness",
enable_coverage=True,
enable_pypi_publish=True,
),
]:

ids.append(case.id)
argvalues.append(
[
case.github_user,
case.enable_coverage,
case.enable_pypi_publish,
f"tests/data/readme-{case.id}.md",
]
)
return ParametrizeParams(
argnames=argnames, argvalues=argvalues, ids=ids
)
35 changes: 35 additions & 0 deletions tests/test_cookiecutter.py → tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
import yaml

from .readme_utils import ReadmeCases

TEMPLATE_ONLY_DATA = "cookiecutter_template_data"


Expand Down Expand Up @@ -95,6 +97,7 @@ def test_rendered_project(cookies: Any) -> None:
project_description=(
'This is a test project called "test-baked-cookie"'
),
github_user="ness",
),
)

Expand Down Expand Up @@ -123,3 +126,35 @@ def test_rendered_project(cookies: Any) -> None:
subprocess.check_call(
["poetry", "run", "poe", "test"], cwd=result.project_path
)


@pytest.mark.parametrize(**ReadmeCases.all_cases().__dict__)
def test_rendered_readme(
cookies: Any,
github_user: str,
enable_coverage: bool,
enable_pypi_publish: bool,
expected_content_file: str,
opt_update_expected_outputs: bool,
) -> None:
result = _bake(
cookies,
extra_context=dict(
author_name="Ness",
author_email="pk-fire@onett.example.com",
project_name="test-baked-cookie",
project_description=(
'This is a test project called "test-baked-cookie"'
),
github_user=github_user,
enable_coverage=("yes" if enable_coverage else "no"),
enable_pypi_publish=("yes" if enable_pypi_publish else "no"),
),
)

readme = open(os.path.join(result.project_path, "README.md"), "r").read()
if opt_update_expected_outputs:
with open(expected_content_file, "w") as f:
f.write(readme)

assert readme == open(expected_content_file, "r").read()
Loading
0