From ec460eb53eea4558159187e4211bb57eb63fccfb Mon Sep 17 00:00:00 2001 From: Hans Then Date: Mon, 9 Jun 2025 15:38:09 +0200 Subject: [PATCH 1/5] Add coverage testing --- .github/workflows/test_code.yml | 2 +- .github/workflows/test_geopandas.yml | 2 +- .github/workflows/test_latest_branca.yml | 2 +- .github/workflows/test_selenium.yml | 2 +- .github/workflows/test_snapshots.yml | 2 +- .github/workflows/test_streamlit_folium.yml | 2 +- folium/__init__.py | 7 +++++-- tests/snapshots/test_snapshots.py | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test_code.yml b/.github/workflows/test_code.yml index e29dd68f20..80d3a60e26 100644 --- a/.github/workflows/test_code.yml +++ b/.github/workflows/test_code.yml @@ -41,4 +41,4 @@ jobs: pip install pixelmatch - name: Code tests - run: python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + run: coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots diff --git a/.github/workflows/test_geopandas.yml b/.github/workflows/test_geopandas.yml index a7ed868b47..e67e6d1509 100644 --- a/.github/workflows/test_geopandas.yml +++ b/.github/workflows/test_geopandas.yml @@ -46,4 +46,4 @@ jobs: - name: Run Geopandas tests run: | cd geopandas - pytest -r a geopandas/tests/test_explore.py + coverage run -p -m pytest -r a geopandas/tests/test_explore.py diff --git a/.github/workflows/test_latest_branca.yml b/.github/workflows/test_latest_branca.yml index c7ea3aaa19..c8e490ec8f 100644 --- a/.github/workflows/test_latest_branca.yml +++ b/.github/workflows/test_latest_branca.yml @@ -33,4 +33,4 @@ jobs: run: | micromamba remove branca --yes --force python -m pip install git+https://github.com/python-visualization/branca.git - python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots diff --git a/.github/workflows/test_selenium.yml b/.github/workflows/test_selenium.yml index 61a87df02c..45389f30eb 100644 --- a/.github/workflows/test_selenium.yml +++ b/.github/workflows/test_selenium.yml @@ -34,4 +34,4 @@ jobs: - name: Selenium tests shell: bash -l {0} - run: python -m pytest tests/selenium -vv + run: coverage run -p -m pytest tests/selenium -vv diff --git a/.github/workflows/test_snapshots.yml b/.github/workflows/test_snapshots.yml index 9555eff44e..ffba05d185 100644 --- a/.github/workflows/test_snapshots.yml +++ b/.github/workflows/test_snapshots.yml @@ -36,7 +36,7 @@ jobs: - name: Test with pytest shell: bash -l {0} run: | - python -m pytest tests/snapshots -s --junit-xml=test-results.xml + coverage run -p -m pytest tests/snapshots -s --junit-xml=test-results.xml - name: Surface failing tests if: always() diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index d821a0c140..f9b2ad58fc 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -66,7 +66,7 @@ jobs: shell: bash -l {0} run: | cd streamlit_folium - pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" --junit-xml=test-results.xml + coverage run -p -m tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" - name: Surface failing tests if: always() diff --git a/folium/__init__.py b/folium/__init__.py index c6fa376e4c..67489f8c50 100644 --- a/folium/__init__.py +++ b/folium/__init__.py @@ -46,13 +46,16 @@ try: from ._version import __version__ -except ImportError: +except ImportError: # pragma: no cover __version__ = "unknown" if branca.__version__ != "unknown" and tuple( int(x) for x in branca.__version__.split(".")[:2] -) < (0, 3): +) < ( + 0, + 3, +): # pragma: no cover raise ImportError( "branca version 0.3.0 or higher is required. " "Update branca with e.g. `pip install branca --upgrade`." diff --git a/tests/snapshots/test_snapshots.py b/tests/snapshots/test_snapshots.py index 84c20211ba..8249bc1686 100644 --- a/tests/snapshots/test_snapshots.py +++ b/tests/snapshots/test_snapshots.py @@ -35,7 +35,7 @@ def test_screenshot(path: str): m.save(f"/tmp/folium_map_{path}.html") assert mismatch < 200 - else: + else: # pragma: no cover shutil.copy( f"/tmp/screenshot_new_{path}.png", f"tests/snapshots/screenshots/screenshot_{path}.png", From d3020f78a90eeae64d90e09a6c7d9777608a41b9 Mon Sep 17 00:00:00 2001 From: Hans Then Date: Mon, 9 Jun 2025 16:57:37 +0200 Subject: [PATCH 2/5] Add code coverage to test runs --- .github/workflows/save_coverage.yml | 34 +++++++++++++++++++++ .github/workflows/test_code.yml | 8 +++++ .github/workflows/test_geopandas.yml | 8 +++++ .github/workflows/test_latest_branca.yml | 8 +++++ .github/workflows/test_selenium.yml | 8 +++++ .github/workflows/test_snapshots.yml | 8 +++++ .github/workflows/test_streamlit_folium.yml | 9 ++++++ 7 files changed, 83 insertions(+) create mode 100644 .github/workflows/save_coverage.yml diff --git a/.github/workflows/save_coverage.yml b/.github/workflows/save_coverage.yml new file mode 100644 index 0000000000..5e4641ec9c --- /dev/null +++ b/.github/workflows/save_coverage.yml @@ -0,0 +1,34 @@ +name: Upload coverage + +on: + workflow_run: + workflows: ['Code Tests', 'Geopandas tests', 'Code Tests with Latest branca', 'Selenium Tests', 'Run Snapshot Tests', 'Run Streamlit Folium Tests'] + types: [completed] + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Download coverage files from previous steps + id: download-artifacts + uses: actions/download-artifact@v4 + with: + path: combined-coverage + pattern: coverage-* + merge-multiple: true + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Combine coverage + run: coverage combine + + - name: Generate report + run: coverage html --skip-covered + + - name: Upload coverage report + if: always() + uses: actions/upload-artifact@v4 + with: + name: combined-coverage + path: htmlcov/** + fail-on-empty: false diff --git a/.github/workflows/test_code.yml b/.github/workflows/test_code.yml index 80d3a60e26..ab966c9e29 100644 --- a/.github/workflows/test_code.yml +++ b/.github/workflows/test_code.yml @@ -42,3 +42,11 @@ jobs: - name: Code tests run: coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-code + path: | + .coverage* diff --git a/.github/workflows/test_geopandas.yml b/.github/workflows/test_geopandas.yml index e67e6d1509..219b3db194 100644 --- a/.github/workflows/test_geopandas.yml +++ b/.github/workflows/test_geopandas.yml @@ -47,3 +47,11 @@ jobs: run: | cd geopandas coverage run -p -m pytest -r a geopandas/tests/test_explore.py + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-geopandas + path: | + .coverage* diff --git a/.github/workflows/test_latest_branca.yml b/.github/workflows/test_latest_branca.yml index c8e490ec8f..0f0f4ea70e 100644 --- a/.github/workflows/test_latest_branca.yml +++ b/.github/workflows/test_latest_branca.yml @@ -34,3 +34,11 @@ jobs: micromamba remove branca --yes --force python -m pip install git+https://github.com/python-visualization/branca.git coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-branca + path: | + .coverage* diff --git a/.github/workflows/test_selenium.yml b/.github/workflows/test_selenium.yml index 45389f30eb..e1d876d33c 100644 --- a/.github/workflows/test_selenium.yml +++ b/.github/workflows/test_selenium.yml @@ -35,3 +35,11 @@ jobs: - name: Selenium tests shell: bash -l {0} run: coverage run -p -m pytest tests/selenium -vv + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-selenium + path: | + .coverage* diff --git a/.github/workflows/test_snapshots.yml b/.github/workflows/test_snapshots.yml index ffba05d185..14cac92028 100644 --- a/.github/workflows/test_snapshots.yml +++ b/.github/workflows/test_snapshots.yml @@ -53,3 +53,11 @@ jobs: path: | /tmp/screenshot_*_*.png /tmp/folium_map_*.html + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-snapshots + path: | + .coverage* diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index f9b2ad58fc..19e4026fd5 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -74,3 +74,12 @@ jobs: with: path: streamlit_folium/test-results.xml fail-on-empty: false + + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-streamlit-folium + path: | + .coverage* From 05e6d708ad6acccbda027c33d860f4990337e11f Mon Sep 17 00:00:00 2001 From: Hans Then Date: Mon, 9 Jun 2025 22:18:57 +0200 Subject: [PATCH 3/5] Install coverage package --- .github/workflows/test_streamlit_folium.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index 19e4026fd5..ffe0ff89d6 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -55,7 +55,7 @@ jobs: playwright install --with-deps - name: Install annotate-failures-plugin - run: pip install pytest-github-actions-annotate-failures + run: pip install pytest-github-actions-annotate-failures coverage - name: Install folium from source shell: bash -l {0} From a520b55560e2eaf4b4d29e9863c6d5e207282ffc Mon Sep 17 00:00:00 2001 From: Hans Then Date: Mon, 9 Jun 2025 22:29:39 +0200 Subject: [PATCH 4/5] Fix missing pytest statement. --- .github/workflows/test_streamlit_folium.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index ffe0ff89d6..17b071349e 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -66,7 +66,7 @@ jobs: shell: bash -l {0} run: | cd streamlit_folium - coverage run -p -m tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" + coverage run -p -m pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" - name: Surface failing tests if: always() From 6946ef4e355583dafbba4a9ef13f18ddeacff3ea Mon Sep 17 00:00:00 2001 From: Hans Then Date: Mon, 9 Jun 2025 22:42:16 +0200 Subject: [PATCH 5/5] Trial and error --- .github/workflows/test_streamlit_folium.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index 17b071349e..0ba8d449c8 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -66,7 +66,7 @@ jobs: shell: bash -l {0} run: | cd streamlit_folium - coverage run -p -m pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" + python -m pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" - name: Surface failing tests if: always()