-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π§ͺ π§ add test configuration to pytest and coverage * π§ πͺ repos with - instead of _ * π§ͺ β add pytest to πͺ and makefile * β add pytest-cov pytest-cookies * π§ β add codecov.yml file * π· add test github action * π add codecov badge to readme
- Loading branch information
1 parent
c95d444
commit 33deb63
Showing
11 changed files
with
518 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
actionlint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Download actionlint | ||
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) 1.6.21 | ||
shell: bash | ||
- name: Check workflow files | ||
run: ./actionlint -color | ||
shell: bash | ||
|
||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./.github/actions/python-poetry-env | ||
- run: poetry run pre-commit run --all-files | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.11"] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ./.github/actions/python-poetry-env | ||
#{% raw %} | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
#{% endraw %} | ||
- name: Run pytest with coverage | ||
run: poetry run pytest --cov=./ --cov-report=xml | ||
|
||
#{% raw %} | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v4 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
slug: JoseRZapata/data-science-project-template | ||
#{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
codecov: | ||
notify: | ||
require_ci_to_pass: no | ||
after_n_builds: 1 # how many uploads per commit | ||
wait_for_ci: no | ||
|
||
|
||
coverage: | ||
status: | ||
patch: # minimum coverage needed based only on the new code introduced on the PR | ||
default: off | ||
pr_coverage: | ||
target: 90% | ||
project: | ||
default: off | ||
minimum: # minimum target of coverage needed to pass the check | ||
target: 90% | ||
decrement: # maximum decrement of coverage allowed | ||
target: auto | ||
threshold: 0.5% | ||
if_not_found: success | ||
comment: # configuration of the details the bot will comment on the PR | ||
layout: "diff, flags" | ||
behavior: default | ||
require_changes: false # if true: only post the comment if coverage changes | ||
require_base: no # [yes :: must have a base report to post] | ||
require_head: no # [yes :: must have a head report to post] | ||
branches: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"project_name": "Project Name", | ||
"repo_name": "{{ cookiecutter.project_name.strip().replace(' ', '_').replace('-', '_').lower() }}", | ||
"repo_name": "{{ cookiecutter.project_name.strip().replace(' ', '-').replace('_', '-').lower() }}", | ||
"github_username": "", | ||
"author_name": "Peter Parker", | ||
"author_email": "[email protected]", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import re | ||
import subprocess # nosec | ||
|
||
|
||
def build_files_list(root_dir): # type: ignore | ||
"""Build a list containing absolute paths to the generated files.""" | ||
return [ | ||
os.path.join(dirpath, file_path) | ||
for dirpath, _, files in os.walk(root_dir) | ||
for file_path in files | ||
] | ||
|
||
|
||
def test_run_cookiecutter_result(cookies): # type: ignore | ||
"""Runs cookiecutter and checks a couple of things""" | ||
project_name = "data science project template" | ||
repo_name = "data-science-project-template" | ||
result = cookies.bake( | ||
extra_context={"project_name": project_name, "repo_name": repo_name} | ||
) | ||
|
||
assert result.exit_code == 0 | ||
assert result.exception is None | ||
assert result.project_path.name == repo_name | ||
assert result.project_path.is_dir() | ||
|
||
readme_path = result.project_path / "README.md" | ||
assert readme_path.is_file() | ||
|
||
with open(readme_path) as f: | ||
readme = f.read() | ||
assert project_name in readme | ||
assert "project_name" not in readme | ||
|
||
|
||
def test_cookiecutter_generated_files(cookies): # type: ignore | ||
"""tests the generated files names make sense""" | ||
re_bad = re.compile(r"{{\s?cookiecutter\..*?}}") | ||
result = cookies.bake() | ||
|
||
assert all( | ||
re_bad.search(str(file_path)) is None | ||
for file_path in result.project_path.glob("*") | ||
) | ||
|
||
|
||
def test_cookiecutter_make_help(cookies): # type: ignore | ||
"""ensure the make help command runs without error""" | ||
result = cookies.bake() | ||
|
||
make_proc = subprocess.Popen( | ||
["/usr/bin/make"], | ||
shell=False, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.STDOUT, | ||
cwd=result.project_path, | ||
) # nosec | ||
# stdout, stderr are for debuggin | ||
stdout, stderr = make_proc.communicate() | ||
assert make_proc.returncode == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def test_cookiecutter_conf_files(cookies) -> None: # type: ignore | ||
"""ensures the codecov files not present""" | ||
codecov = False | ||
result = cookies.bake(extra_context={"codecov": codecov}) | ||
|
||
env_path = result.project_path / ".github/workflows/test.yml" | ||
assert env_path.is_file() | ||
|
||
with open(env_path) as f: | ||
file_content = f.read() | ||
assert "CODECOV_TOKEN" not in file_content | ||
|
||
env_path = result.project_path / "codecov.yml" | ||
assert not env_path.is_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
def test_cookiecutter_mkdocs_files(cookies) -> None: # type: ignore | ||
"""ensures the mkdocs files not present""" | ||
mkdocs = False | ||
result = cookies.bake(extra_context={"mkdocs": mkdocs}) | ||
|
||
env_path = result.project_path / "mkdocs.yml" | ||
assert not env_path.is_file() | ||
|
||
env_path = result.project_path / ".github/workflows/docs.yml" | ||
assert not env_path.is_file() | ||
|
||
env_path = result.project_path / "docs/index.md" | ||
assert not env_path.is_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters