Skip to content

Commit

Permalink
Simplify coverage and lint actions v2 (#435)
Browse files Browse the repository at this point in the history
* simplify coverage and lint actions

* move around the testing for coverage

* try 3.11

* clean up a bit

* separate tests

* run tests twice

* no coverage target for cython tests

* full tests for polygon_to_cells_experimental

* i think that gets the actions how we want
  • Loading branch information
ajfriend authored Dec 29, 2024
1 parent ef6e897 commit 3d5b12a
Show file tree
Hide file tree
Showing 26 changed files with 95 additions and 83 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/coverage-lint-pr.yml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/coverage-lint.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/lint_and_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: lint_and_coverage

on:
push:
branches: [master]
pull_request:
branches: ['*']

jobs:
linting:
name: Lint and Coverage
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install from source
run: pip install .[test]

- name: Run Linting
uses: astral-sh/ruff-action@v3

- name: Coverage Requirement - Library
run: |
pytest --cov=tests/test_lib --cov-fail-under=100
- name: Coverage - Cython
run: |
pip install cython
cythonize tests/test_cython/cython_example.pyx
pytest --cov=tests/test_cython
4 changes: 3 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ purge: clear
-@rm -rf env

test:
./env/bin/pytest --cov=tests/test_lib --cov-fail-under=100

./env/bin/pip install cython
./env/bin/cythonize tests/test_cython/cython_example.pyx
./env/bin/pytest
./env/bin/pytest --cov=tests/test_cython

lint:
./env/bin/ruff check
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ all = [
]

[tool.pytest.ini_options]
addopts = "--cov=h3 --cov=tests --cov-report=term-missing --durations=10"
addopts = "--cov=h3 --cov-report=term-missing --durations=10"

[tool.coverage.run]
omit = [
Expand Down
18 changes: 18 additions & 0 deletions tests/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
We separate the `h3-py` tests into two groups, organized by subfolder.

We do this because we expect 100% coverage on the library tests, but are
still working through getting full coverage on the Cython tests.


## `test_lib`

The tests in this folder are for the main `h3-py` Python API for folks
who are using the pure-Python library functionality.

## `test_cython`

The tests in this folder are for the advanced Cython API, that allows
for other *Cython* packages or scripts to use the Cython code provided
by the `h3-py` internals.

Note that the "Cython API" of `h3-py` is not currently externally supported.
File renamed without changes.
File renamed without changes.
30 changes: 29 additions & 1 deletion tests/polyfill/test_h3.py → tests/test_lib/polyfill/test_h3.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,39 @@ def test_polygon_to_cells_experimental_invalid_mode():
poly = h3.LatLngPoly(sf_7x7)
for flags in [1.0, 'containment_overlapping_bbox_abc', None]:
with pytest.raises(ValueError):
print(flags)
# Note that `polygon_to_cells` is an alias for `h3shape_to_cells`
h3.polygon_to_cells_experimental(poly, res=9, flags=flags)


def test_poly_to_cells_experimental_mpoly():
mpoly = h3.LatLngMultiPoly(
h3.LatLngPoly(sf_hole1),
h3.LatLngPoly(sf_hole2),
)

assert (
set(h3.polygon_to_cells_experimental(mpoly, res=9))
==
set(h3.polygon_to_cells_experimental(mpoly, res=9, flags='containment_center'))
)

assert (
set(h3.polygon_to_cells_experimental(mpoly, res=9))
<
set(h3.polygon_to_cells_experimental(
mpoly,
res=9,
flags='containment_overlapping'
))
)

assert 120 == len(h3.polygon_to_cells_experimental(
mpoly,
res=9,
flags='containment_overlapping'
))


def test_polyfill_with_hole():
poly = h3.LatLngPoly(sf_7x7, sf_hole1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def test_bad_geo_input():
with pytest.raises(ValueError):
h3.h3shape_to_cells('not a shape', 9)

with pytest.raises(ValueError):
h3.h3shape_to_cells_experimental('not a shape', res=9)

with pytest.raises(ValueError):
h3.geo_to_cells({'type': 'not a shape', 'coordinates': None}, 9)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,9 @@ def __geo_interface__(self):

shoop = H3Shoop()
shoop.__geo_interface__()

with pytest.raises(ValueError):
h3.h3shape_to_cells(shoop, res=9)

with pytest.raises(ValueError):
h3.h3shape_to_cells_experimental(shoop, res=9)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 3d5b12a

Please sign in to comment.