Skip to content

Commit 3d5b12a

Browse files
authored
Simplify coverage and lint actions v2 (#435)
* 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
1 parent ef6e897 commit 3d5b12a

26 files changed

+95
-83
lines changed

.github/workflows/coverage-lint-pr.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/coverage-lint.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: lint_and_coverage
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: ['*']
8+
9+
jobs:
10+
linting:
11+
name: Lint and Coverage
12+
runs-on: ubuntu-24.04
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.11
22+
23+
- name: Install from source
24+
run: pip install .[test]
25+
26+
- name: Run Linting
27+
uses: astral-sh/ruff-action@v3
28+
29+
- name: Coverage Requirement - Library
30+
run: |
31+
pytest --cov=tests/test_lib --cov-fail-under=100
32+
33+
- name: Coverage - Cython
34+
run: |
35+
pip install cython
36+
cythonize tests/test_cython/cython_example.pyx
37+
pytest --cov=tests/test_cython

makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ purge: clear
3535
-@rm -rf env
3636

3737
test:
38+
./env/bin/pytest --cov=tests/test_lib --cov-fail-under=100
39+
3840
./env/bin/pip install cython
3941
./env/bin/cythonize tests/test_cython/cython_example.pyx
40-
./env/bin/pytest
42+
./env/bin/pytest --cov=tests/test_cython
4143

4244
lint:
4345
./env/bin/ruff check

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ all = [
6363
]
6464

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

6868
[tool.coverage.run]
6969
omit = [

tests/readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
We separate the `h3-py` tests into two groups, organized by subfolder.
2+
3+
We do this because we expect 100% coverage on the library tests, but are
4+
still working through getting full coverage on the Cython tests.
5+
6+
7+
## `test_lib`
8+
9+
The tests in this folder are for the main `h3-py` Python API for folks
10+
who are using the pure-Python library functionality.
11+
12+
## `test_cython`
13+
14+
The tests in this folder are for the advanced Cython API, that allows
15+
for other *Cython* packages or scripts to use the Cython code provided
16+
by the `h3-py` internals.
17+
18+
Note that the "Cython API" of `h3-py` is not currently externally supported.
File renamed without changes.
File renamed without changes.

tests/polyfill/test_h3.py renamed to tests/test_lib/polyfill/test_h3.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,39 @@ def test_polygon_to_cells_experimental_invalid_mode():
174174
poly = h3.LatLngPoly(sf_7x7)
175175
for flags in [1.0, 'containment_overlapping_bbox_abc', None]:
176176
with pytest.raises(ValueError):
177-
print(flags)
178177
# Note that `polygon_to_cells` is an alias for `h3shape_to_cells`
179178
h3.polygon_to_cells_experimental(poly, res=9, flags=flags)
180179

181180

181+
def test_poly_to_cells_experimental_mpoly():
182+
mpoly = h3.LatLngMultiPoly(
183+
h3.LatLngPoly(sf_hole1),
184+
h3.LatLngPoly(sf_hole2),
185+
)
186+
187+
assert (
188+
set(h3.polygon_to_cells_experimental(mpoly, res=9))
189+
==
190+
set(h3.polygon_to_cells_experimental(mpoly, res=9, flags='containment_center'))
191+
)
192+
193+
assert (
194+
set(h3.polygon_to_cells_experimental(mpoly, res=9))
195+
<
196+
set(h3.polygon_to_cells_experimental(
197+
mpoly,
198+
res=9,
199+
flags='containment_overlapping'
200+
))
201+
)
202+
203+
assert 120 == len(h3.polygon_to_cells_experimental(
204+
mpoly,
205+
res=9,
206+
flags='containment_overlapping'
207+
))
208+
209+
182210
def test_polyfill_with_hole():
183211
poly = h3.LatLngPoly(sf_7x7, sf_hole1)
184212

tests/polyfill/test_polyfill.py renamed to tests/test_lib/polyfill/test_polyfill.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def test_bad_geo_input():
145145
with pytest.raises(ValueError):
146146
h3.h3shape_to_cells('not a shape', 9)
147147

148+
with pytest.raises(ValueError):
149+
h3.h3shape_to_cells_experimental('not a shape', res=9)
150+
148151
with pytest.raises(ValueError):
149152
h3.geo_to_cells({'type': 'not a shape', 'coordinates': None}, 9)
150153

tests/polyfill/test_polygon_class.py renamed to tests/test_lib/polyfill/test_polygon_class.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,9 @@ def __geo_interface__(self):
4444

4545
shoop = H3Shoop()
4646
shoop.__geo_interface__()
47+
4748
with pytest.raises(ValueError):
4849
h3.h3shape_to_cells(shoop, res=9)
50+
51+
with pytest.raises(ValueError):
52+
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.

0 commit comments

Comments
 (0)