Skip to content

Commit

Permalink
Run tests and coverage with GH Actions (#22)
Browse files Browse the repository at this point in the history
* Setup actions wf for testing and coverage.
* Use tox for testing and coverage for coverage
* move tests to src directory
* report status with badges in README
  • Loading branch information
joergdietrich authored Dec 30, 2022
1 parent 0a0325e commit 9a7f308
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 5 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: "Test Suite"

on:
push:
pull_request:

jobs:
tests:
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"

strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"

- name: "Set up Python"
uses: "actions/setup-python@v3"
with:
python-version: "${{ matrix.python-version }}"

- name: "Install dependencies"
run: |
python -m pip install tox tox-gh-actions
- name: "Run tox for ${{ matrix.python-version }}"
run: |
python -m tox
- name: "Upload coverage data"
uses: actions/upload-artifact@v3
with:
name: covdata
path: .coverage.*

coverage:
name: Coverage
needs: tests
runs-on: ubuntu-latest
steps:
- name: "Check out the repo"
uses: "actions/checkout@v3"

- name: "Set up Python"
uses: "actions/setup-python@v3"
with:
python-version: "3.11"

- name: "Install dependencies"
run: |
python -m pip install tox tox-gh-actions
- name: "Download coverage data"
uses: actions/download-artifact@v3
with:
name: covdata

- name: "Combine"
run: |
python -m tox -e coverage
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "total=$TOTAL" >> $GITHUB_ENV
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
- name: "Make badge"
uses: schneegans/[email protected]
with:
# GIST_TOKEN is a GitHub personal access token with scope "gist".
auth: ${{ secrets.GIST_TOKEN }}
gistID: 9deb619232c8098b5e15d259ef5ed534
filename: covbadge.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ dist
/daltonize.egg-info/
.ipynb_checkpoints/
doc/colourmaps.pdf
.vscode
.coverage
.tox
coverage.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Daltonize

![https://github.com/joergdietrich/daltonize/actions](https://img.shields.io/github/actions/workflow/status/joergdietrich/daltonize/main.yml) ![](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/joergdietrich/9deb619232c8098b5e15d259ef5ed534/raw/covbadge.json)

Daltonize simulates the three types of dichromatic color blindness and
images and matplotlib figures. Generalizing and omitting a lot of
details these types are:
Expand Down
3 changes: 3 additions & 0 deletions daltonize/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__all__ = ['daltonize']

__version__ = "0.2.0"
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
8 changes: 4 additions & 4 deletions tests/test_daltonize.py → daltonize/tests/test_daltonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_inverse_gamma_correction():
rgb = np.array([[[0, 10, 11, 25, 128, 255]]]).reshape((-1, 1, 3))
assert_array_almost_equal(rgb, inverse_gamma_correction(gamma_correction(rgb)))

@pytest.mark.parametrize("type, ref_img_path", [("d", Path("data/colored_crayons_d.png")),
("p", Path("data/colored_crayons_p.png")),
("t", Path("data/colored_crayons_t.png"))])
@pytest.mark.parametrize("type, ref_img_path", [("d", Path("daltonize/tests/data/colored_crayons_d.png")),
("p", Path("daltonize/tests/data/colored_crayons_p.png")),
("t", Path("daltonize/tests/data/colored_crayons_t.png"))])
def test_simulation(type, ref_img_path):
gamma = 2.4
orig_img_path = Path("data/colored_crayons.png")
orig_img_path = Path("daltonize/tests/data/colored_crayons.png")
orig_img = np.asarray(Image.open(orig_img_path).convert("RGB"), dtype=np.float16)
orig_img = gamma_correction(orig_img, gamma)
simul_rgb = simulate(orig_img, type)
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import setuptools

import daltonize

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="daltonize", # Replace with your own username
version="0.1.2",
version=daltonize.__version__,
author="Jörg Dietrich",
author_email="[email protected]",
description="simulate and correct for color blindness in matplotlib figures and images",
Expand Down
31 changes: 31 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[tox]
env_list =
py37,py38,py39,py310,py311,coverage
minversion = 4.0.16

[testenv]
deps =
coverage
pytest
commands =
python -m coverage run -p -m pytest

[testenv:coverage]
basepython = python3.11
depends = py37,py38,py39,py310,py311
parallel_show_output = true
commands =
python -m coverage combine
python -m coverage report -m --skip-covered
python -m coverage json

[coverage:run]
relative_files = True

[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311

0 comments on commit 9a7f308

Please sign in to comment.