From 3d5b12a37071a09248389cafe8f45032c9a9a549 Mon Sep 17 00:00:00 2001 From: AJ Friend Date: Sun, 29 Dec 2024 11:15:46 -0800 Subject: [PATCH] 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 --- .github/workflows/coverage-lint-pr.yml | 40 ------------------- .github/workflows/coverage-lint.yml | 40 ------------------- .github/workflows/lint_and_coverage.yml | 37 +++++++++++++++++ makefile | 4 +- pyproject.toml | 2 +- tests/readme.md | 18 +++++++++ tests/{ => test_lib}/__init__.py | 0 tests/{ => test_lib}/polyfill/__init__.py | 0 tests/{ => test_lib}/polyfill/test_h3.py | 30 +++++++++++++- .../{ => test_lib}/polyfill/test_polyfill.py | 3 ++ .../polyfill/test_polyfill_ordering.py | 0 .../polyfill/test_polygon_class.py | 4 ++ .../polyfill/test_to_multipoly.py | 0 tests/{ => test_lib}/test_apis/__init__.py | 0 .../test_apis/test_api_bindings_match.py | 0 .../test_apis/test_basic_int.py | 0 .../test_apis/test_basic_str.py | 0 .../test_apis/test_collection_inputs.py | 0 .../test_apis/test_ico_faces.py | 0 .../test_apis/test_memview_int.py | 0 .../test_apis/test_numpy_int.py | 0 tests/{ => test_lib}/test_cells_and_edges.py | 0 tests/{ => test_lib}/test_error_codes.py | 0 tests/{ => test_lib}/test_h3.py | 0 tests/{ => test_lib}/test_length_area.py | 0 tests/{ => test_lib}/util.py | 0 26 files changed, 95 insertions(+), 83 deletions(-) delete mode 100644 .github/workflows/coverage-lint-pr.yml delete mode 100644 .github/workflows/coverage-lint.yml create mode 100644 .github/workflows/lint_and_coverage.yml create mode 100644 tests/readme.md rename tests/{ => test_lib}/__init__.py (100%) rename tests/{ => test_lib}/polyfill/__init__.py (100%) rename tests/{ => test_lib}/polyfill/test_h3.py (94%) rename tests/{ => test_lib}/polyfill/test_polyfill.py (97%) rename tests/{ => test_lib}/polyfill/test_polyfill_ordering.py (100%) rename tests/{ => test_lib}/polyfill/test_polygon_class.py (91%) rename tests/{ => test_lib}/polyfill/test_to_multipoly.py (100%) rename tests/{ => test_lib}/test_apis/__init__.py (100%) rename tests/{ => test_lib}/test_apis/test_api_bindings_match.py (100%) rename tests/{ => test_lib}/test_apis/test_basic_int.py (100%) rename tests/{ => test_lib}/test_apis/test_basic_str.py (100%) rename tests/{ => test_lib}/test_apis/test_collection_inputs.py (100%) rename tests/{ => test_lib}/test_apis/test_ico_faces.py (100%) rename tests/{ => test_lib}/test_apis/test_memview_int.py (100%) rename tests/{ => test_lib}/test_apis/test_numpy_int.py (100%) rename tests/{ => test_lib}/test_cells_and_edges.py (100%) rename tests/{ => test_lib}/test_error_codes.py (100%) rename tests/{ => test_lib}/test_h3.py (100%) rename tests/{ => test_lib}/test_length_area.py (100%) rename tests/{ => test_lib}/util.py (100%) diff --git a/.github/workflows/coverage-lint-pr.yml b/.github/workflows/coverage-lint-pr.yml deleted file mode 100644 index 5db848c14..000000000 --- a/.github/workflows/coverage-lint-pr.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: pr-coverage-lint - -on: - pull_request: - branches: ['*'] - -jobs: - tests: - name: Coverage and Lint - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4.2.2 - with: - submodules: recursive - - - uses: actions/setup-python@v5.3.0 - with: - python-version: 3.11 - - - name: Install from source - run: | - pip install --upgrade pip setuptools wheel - pip install .[test] - - - name: Run Linting - uses: astral-sh/ruff-action@v1.1.1 - - - name: Coverage - run: | - pip install cython - cythonize tests/test_cython/cython_example.pyx - pytest --cov-report=lcov - - - name: Report coverage - uses: romeovs/lcov-reporter-action@v0.3.1 - with: - filter-changed-files: true - github-token: ${{ secrets.GITHUB_TOKEN }} - lcov-file: ./coverage.lcov diff --git a/.github/workflows/coverage-lint.yml b/.github/workflows/coverage-lint.yml deleted file mode 100644 index ab0d52bbe..000000000 --- a/.github/workflows/coverage-lint.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: coverage-lint - -on: - push: - branches: [master] - -jobs: - tests: - name: Coverage and Lint - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v4.2.2 - with: - submodules: recursive - - - uses: actions/setup-python@v5.3.0 - with: - python-version: 3.11 - - - name: Install from source - run: | - pip install --upgrade pip setuptools wheel - pip install .[test] - - - name: Run Linting - uses: astral-sh/ruff-action@v1.1.1 - - - name: Coverage - run: | - pip install cython - cythonize tests/test_cython/cython_example.pyx - pytest --cov-report=xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4.3.0 - with: - file: ./coverage.xml - fail_ci_if_error: true - token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/lint_and_coverage.yml b/.github/workflows/lint_and_coverage.yml new file mode 100644 index 000000000..ab23b27c1 --- /dev/null +++ b/.github/workflows/lint_and_coverage.yml @@ -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 diff --git a/makefile b/makefile index 6c06e636c..e6b02837d 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 93cb37d38..e1cc0ba95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/tests/readme.md b/tests/readme.md new file mode 100644 index 000000000..0aba346c5 --- /dev/null +++ b/tests/readme.md @@ -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. diff --git a/tests/__init__.py b/tests/test_lib/__init__.py similarity index 100% rename from tests/__init__.py rename to tests/test_lib/__init__.py diff --git a/tests/polyfill/__init__.py b/tests/test_lib/polyfill/__init__.py similarity index 100% rename from tests/polyfill/__init__.py rename to tests/test_lib/polyfill/__init__.py diff --git a/tests/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py similarity index 94% rename from tests/polyfill/test_h3.py rename to tests/test_lib/polyfill/test_h3.py index 50728d353..933f404c3 100644 --- a/tests/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -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) diff --git a/tests/polyfill/test_polyfill.py b/tests/test_lib/polyfill/test_polyfill.py similarity index 97% rename from tests/polyfill/test_polyfill.py rename to tests/test_lib/polyfill/test_polyfill.py index 1431b8765..9bdd9af99 100644 --- a/tests/polyfill/test_polyfill.py +++ b/tests/test_lib/polyfill/test_polyfill.py @@ -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) diff --git a/tests/polyfill/test_polyfill_ordering.py b/tests/test_lib/polyfill/test_polyfill_ordering.py similarity index 100% rename from tests/polyfill/test_polyfill_ordering.py rename to tests/test_lib/polyfill/test_polyfill_ordering.py diff --git a/tests/polyfill/test_polygon_class.py b/tests/test_lib/polyfill/test_polygon_class.py similarity index 91% rename from tests/polyfill/test_polygon_class.py rename to tests/test_lib/polyfill/test_polygon_class.py index 3996d3026..59e8da27c 100644 --- a/tests/polyfill/test_polygon_class.py +++ b/tests/test_lib/polyfill/test_polygon_class.py @@ -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) diff --git a/tests/polyfill/test_to_multipoly.py b/tests/test_lib/polyfill/test_to_multipoly.py similarity index 100% rename from tests/polyfill/test_to_multipoly.py rename to tests/test_lib/polyfill/test_to_multipoly.py diff --git a/tests/test_apis/__init__.py b/tests/test_lib/test_apis/__init__.py similarity index 100% rename from tests/test_apis/__init__.py rename to tests/test_lib/test_apis/__init__.py diff --git a/tests/test_apis/test_api_bindings_match.py b/tests/test_lib/test_apis/test_api_bindings_match.py similarity index 100% rename from tests/test_apis/test_api_bindings_match.py rename to tests/test_lib/test_apis/test_api_bindings_match.py diff --git a/tests/test_apis/test_basic_int.py b/tests/test_lib/test_apis/test_basic_int.py similarity index 100% rename from tests/test_apis/test_basic_int.py rename to tests/test_lib/test_apis/test_basic_int.py diff --git a/tests/test_apis/test_basic_str.py b/tests/test_lib/test_apis/test_basic_str.py similarity index 100% rename from tests/test_apis/test_basic_str.py rename to tests/test_lib/test_apis/test_basic_str.py diff --git a/tests/test_apis/test_collection_inputs.py b/tests/test_lib/test_apis/test_collection_inputs.py similarity index 100% rename from tests/test_apis/test_collection_inputs.py rename to tests/test_lib/test_apis/test_collection_inputs.py diff --git a/tests/test_apis/test_ico_faces.py b/tests/test_lib/test_apis/test_ico_faces.py similarity index 100% rename from tests/test_apis/test_ico_faces.py rename to tests/test_lib/test_apis/test_ico_faces.py diff --git a/tests/test_apis/test_memview_int.py b/tests/test_lib/test_apis/test_memview_int.py similarity index 100% rename from tests/test_apis/test_memview_int.py rename to tests/test_lib/test_apis/test_memview_int.py diff --git a/tests/test_apis/test_numpy_int.py b/tests/test_lib/test_apis/test_numpy_int.py similarity index 100% rename from tests/test_apis/test_numpy_int.py rename to tests/test_lib/test_apis/test_numpy_int.py diff --git a/tests/test_cells_and_edges.py b/tests/test_lib/test_cells_and_edges.py similarity index 100% rename from tests/test_cells_and_edges.py rename to tests/test_lib/test_cells_and_edges.py diff --git a/tests/test_error_codes.py b/tests/test_lib/test_error_codes.py similarity index 100% rename from tests/test_error_codes.py rename to tests/test_lib/test_error_codes.py diff --git a/tests/test_h3.py b/tests/test_lib/test_h3.py similarity index 100% rename from tests/test_h3.py rename to tests/test_lib/test_h3.py diff --git a/tests/test_length_area.py b/tests/test_lib/test_length_area.py similarity index 100% rename from tests/test_length_area.py rename to tests/test_lib/test_length_area.py diff --git a/tests/util.py b/tests/test_lib/util.py similarity index 100% rename from tests/util.py rename to tests/test_lib/util.py