Skip to content

Commit

Permalink
CI tests in generated project (#126)
Browse files Browse the repository at this point in the history
* Add test suite run in GitHub action

* Now yaml file need do be rendered

For tests workflow that will run pytest suite only if option is selected when
generating the project.

* Add pytest and coverage options

* Fix failling test

* Fix code style of generated project

Too much new lines.
  • Loading branch information
oncleben31 authored Jan 23, 2021
1 parent cfd3860 commit e2dbf95
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
6 changes: 1 addition & 5 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@
"class_name_prefix": "{{ cookiecutter.domain_name | replace('_', ' ') | title | replace(' ', '') }}",
"github_user": "oncleben31",
"version": "0.0.0",
"test_suite": ["yes", "no"],
"_copy_without_render": [
".github/workflows/*.yml",
".github/workflows/*.yaml"
]
"test_suite": ["yes", "no"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ jobs:
- name: Run release-drafter
uses: release-drafter/release-drafter@v5.12.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
27 changes: 25 additions & 2 deletions {{cookiecutter.project_name}}/.github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
- name: Check out the repository
uses: actions/checkout@v2.3.4

- name: Set up Python ${{ env.DEFAULT_PYTHON }}
- name: Set up Python {{ "${{ env.DEFAULT_PYTHON }}" }}
uses: actions/setup-python@v2.1.4
with:
python-version: ${{ env.DEFAULT_PYTHON }}
python-version: {{ "${{ env.DEFAULT_PYTHON }}" }}

- name: Upgrade pip
run: |
Expand Down Expand Up @@ -61,3 +61,26 @@ jobs:

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"

{%- if cookiecutter.test_suite == "yes" %}
tests:
runs-on: "ubuntu-latest"
name: Run tests
steps:
- name: Check out code from GitHub
uses: "actions/checkout@v2.3.4"
- name: Setup Python {{ "${{ env.DEFAULT_PYTHON }}" }}
uses: "actions/setup-python@v2.1.4"
with:
python-version: {{ "${{ env.DEFAULT_PYTHON }}" }}
- name: Install requirements
run: python3 -m pip install -r requirements_test.txt
- name: Tests suite
run: |
pytest \
--timeout=9 \
--durations=10 \
-n auto \
-p no:sugar \
tests
{%- endif %}
4 changes: 2 additions & 2 deletions {{cookiecutter.project_name}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ file.
You can use the `pre-commit` settings implemented in this repository to have
linting tool checking your contributions (see deicated section below).

{% if cookiecutter.test_suite == "yes" %}
{% if cookiecutter.test_suite == "yes" -%}
You should also verify that existing [tests](./tests) are still working
and you are encouraged to add new ones.
You can run the tests using the following commands from the root folder:
Expand All @@ -80,7 +80,7 @@ pytest --durations=10 --cov-report term-missing --cov=custom_components.{{cookie

If any of the tests fail, make the necessary changes to the tests as part of
your changes to the integration.
{% endif %}
{%- endif %}

## Pre-commit

Expand Down
11 changes: 11 additions & 0 deletions {{cookiecutter.project_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,14 @@ sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = custom_components.{{ cookiecutter.domain_name }}{% if cookiecutter.test_suite == "yes" %}, tests{% endif %}
combine_as_imports = true

[tool:pytest]
addopts = -qq --cov=custom_components.{{ cookiecutter.domain_name }}
console_output_style = count

[coverage:run]
branch = True

[coverage:report]
show_missing = true
fail_under = 100
1 change: 1 addition & 0 deletions {{cookiecutter.project_name}}/tests/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async def test_options_flow(hass):
entry.add_to_hass(hass)

# Initialize an options flow
await hass.config_entries.async_setup(entry.entry_id)
result = await hass.config_entries.options.async_init(entry.entry_id)

# Verify that the first options step is a user form
Expand Down

0 comments on commit e2dbf95

Please sign in to comment.