Skip to content

Commit

Permalink
Make the tests suite optional (#123)
Browse files Browse the repository at this point in the history
* Add an option for tests in template

* Remove path according to parameter selected

* Add files to be removed accordind to parameters

* Remove some file content according to parameter

* Add file to be removed it no tests suite

* Fix wrong condition when skipping tests suite
  • Loading branch information
oncleben31 committed Jan 21, 2021
1 parent 0c9882a commit a546052
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"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"
Expand Down
22 changes: 22 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#!/usr/bin/env python
import json
import os
import shutil
from pathlib import Path

REMOVE_PATHS = [
{% if cookiecutter.test_suite != "yes" %}
'tests/',
'requirements_dev.txt',
'requirements_test.txt',
'custom_components/__init__.py',
{% endif %}
]

def remove_path():
"""Remove some path according to cookiecutter parameters."""
for path in REMOVE_PATHS:
path = path.strip()
if os.path.isfile(path):
os.remove(path)
elif os.path.isdir(path):
shutil.rmtree(path)



def reindent_cookiecutter_json():
"""Indent .cookiecutter.json using two spaces.
Expand All @@ -22,3 +43,4 @@ def reindent_cookiecutter_json():

if __name__ == "__main__":
reindent_cookiecutter_json()
remove_path()
2 changes: 2 additions & 0 deletions {{cookiecutter.project_name}}/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +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" %}
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 @@ -79,6 +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 %}

## Pre-commit

Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ not_skip = __init__.py
force_sort_within_sections = true
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section = THIRDPARTY
known_first_party = custom_components.{{ cookiecutter.domain_name }}, tests
known_first_party = custom_components.{{ cookiecutter.domain_name }}{% if cookiecutter.test_suite == "yes" %}, tests{% endif %}
combine_as_imports = true

0 comments on commit a546052

Please sign in to comment.