-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CI workflow for linting, tests, and coverage (#21)
* Add real tests and a CI workflow that includes coverage reports * Debug test coverage * Fix coverage output file name * Only trigger CI workflow on push to default branch
- Loading branch information
Showing
12 changed files
with
309 additions
and
61 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,112 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
FORCE_COLOR: "1" | ||
PIP_DISABLE_PIP_VERSION_CHECK: "1" | ||
PIP_NO_PYTHON_VERSION_WARNING: "1" | ||
|
||
jobs: | ||
|
||
lint: | ||
name: Run linter | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install uv 🌟 | ||
uses: astral-sh/setup-uv@v5 | ||
with: | ||
version: ">=0.0.1" | ||
|
||
- name: Lint 🧹 | ||
run: | | ||
uv tool install ruff | ||
ruff check | ||
tests: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install uv 🌟 | ||
uses: astral-sh/setup-uv@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
version: ">=0.0.1" | ||
|
||
- name: Test with python ${{ matrix.python-version }} 🧪 | ||
run: | | ||
uv run --frozen coverage run \ | ||
--data-file .coverage.${{ matrix.python-version }} \ | ||
-m pytest | ||
- name: Upload coverage data 📤 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-data-${{ matrix.python-version }} | ||
path: .coverage.* | ||
include-hidden-files: true | ||
if-no-files-found: ignore | ||
|
||
coverage: | ||
# https://hynek.me/articles/ditch-codecov-python/ | ||
name: Combine coverage reports & fail if below threshold | ||
runs-on: ubuntu-latest | ||
needs: tests | ||
if: always() | ||
|
||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install uv 🌟 | ||
uses: astral-sh/setup-uv@v5 | ||
with: | ||
version: '>=0.0.1' | ||
|
||
- name: Download coverage data 📥 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
pattern: coverage-data-* | ||
merge-multiple: true | ||
|
||
- name: Generate coverage report 📊 | ||
run: | | ||
uv tool install 'coverage[toml]' | ||
coverage combine | ||
coverage html --skip-covered --skip-empty | ||
coverage report --format=markdown >> $GITHUB_STEP_SUMMARY | ||
# Generate report again, this time with a fail-under threshold | ||
coverage report --fail-under=80 | ||
- name: Upload HTML report if coverage check fails | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: html-cov-report | ||
path: htmlcov | ||
if: ${{ failure() }} | ||
|
||
|
File renamed without changes.
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 was deleted.
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
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 |
---|---|---|
|
@@ -3,4 +3,3 @@ | |
|
||
def test_insert_here(): | ||
assert True | ||
|
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,24 @@ | ||
from typer.testing import CliRunner | ||
|
||
from pyprefab.cli import app # type: ignore | ||
|
||
|
||
def test_pyprefab_cli(tmp_path): | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
app, | ||
['pytest_project', '--author', 'Py Test', '--directory', tmp_path], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# project directory populated with tesmplate output should contain | ||
# two folders: src and test | ||
dir_count = 0 | ||
dir_names = [] | ||
for child in tmp_path.iterdir(): | ||
if child.is_dir(): | ||
dir_names.append(child.name) | ||
dir_count += 1 | ||
assert dir_count == 2 | ||
assert 'src' in dir_names | ||
assert 'test' in dir_names |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import subprocess | ||
|
||
from typer.testing import CliRunner | ||
|
||
from pyprefab.cli import app # type: ignore | ||
|
||
# tomllib is not part of the standard library until Python 3.11 | ||
try: | ||
import tomllib # type: ignore | ||
except ModuleNotFoundError: | ||
import tomli as tomllib # type: ignore | ||
|
||
|
||
def test_pyproject(tmp_path): | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
app, | ||
[ | ||
'transporter_logs', | ||
'--author', | ||
"Miles O'Brien", | ||
'--description', | ||
"An app for parsin' transporter logs", | ||
'--directory', | ||
tmp_path, | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
with open(tmp_path / 'pyproject.toml', 'rb') as f: | ||
pyproject = tomllib.load(f) | ||
assert pyproject.get('project', {}).get('name') == 'transporter_logs' | ||
assert pyproject.get('project').get('authors')[0].get('name') == "Miles O'Brien" | ||
assert pyproject.get('project').get('description') == "An app for parsin' transporter logs" | ||
|
||
|
||
def test_build(tmp_path): | ||
"""Files created should build a valid python package.""" | ||
runner = CliRunner() | ||
result = runner.invoke( | ||
app, | ||
[ | ||
'transporter_logs', | ||
'--author', | ||
"Miles O'Brien", | ||
'--description', | ||
"An app for parsin' transporter logs", | ||
'--directory', | ||
tmp_path, | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
|
||
# pyprefab output should be a valid Python package | ||
result = subprocess.run( | ||
['python', '-m', 'build', '--sdist', '--wheel'], capture_output=True, cwd=tmp_path, text=True | ||
) | ||
|
||
assert result.returncode == 0 |
Oops, something went wrong.