Skip to content

Commit 2c2d941

Browse files
authored
New snapshot tests (#2144)
* Add sample playwright tests for folium First try: just do the draw plugin. * Sanitize locations of files * Remove unused streamlit based code for testing * This test is too flaky for me
1 parent 495b331 commit 2c2d941

23 files changed

+543
-4
lines changed

.github/workflows/save_versions.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Save package versions
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Folium
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Micromamba env
18+
uses: mamba-org/setup-micromamba@v2
19+
with:
20+
environment-name: TEST
21+
create-args: >-
22+
python=3
23+
--file requirements.txt
24+
--file requirements-dev.txt
25+
26+
- name: Install folium from source
27+
shell: bash -l {0}
28+
run: |
29+
python -m pip install -e . --no-deps --force-reinstall
30+
31+
- name: Create versions.txt
32+
shell: bash -l {0}
33+
run: |
34+
conda list > /tmp/versions.txt
35+
chromium --version >> /tmp/versions.txt
36+
37+
- name: Save versions.txt
38+
if: always()
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: versions.txt
42+
path: /tmp/versions.txt
43+
fail-on-empty: false

.github/workflows/test_code.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,10 @@ jobs:
3535
- name: Install folium from source
3636
run: python -m pip install -e . --no-deps --force-reinstall
3737

38+
- name: Install pixelmatch
39+
shell: bash -l {0}
40+
run: |
41+
pip install pixelmatch
42+
3843
- name: Code tests
39-
run: python -m pytest -vv --ignore=tests/selenium
44+
run: python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots

.github/workflows/test_latest_branca.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
run: |
3434
micromamba remove branca --yes --force
3535
python -m pip install git+https://github.com/python-visualization/branca.git
36-
python -m pytest -vv --ignore=tests/selenium
36+
python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots

.github/workflows/test_snapshots.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Run Snapshot Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
run:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Folium
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Micromamba env
18+
uses: mamba-org/setup-micromamba@v2
19+
with:
20+
environment-name: TEST
21+
create-args: >-
22+
python=3
23+
--file requirements.txt
24+
--file requirements-dev.txt
25+
26+
- name: Install pytest plugins and pixelmatch
27+
shell: bash -l {0}
28+
run: |
29+
pip install pixelmatch pytest-github-actions-annotate-failures pytest-rerunfailures
30+
31+
- name: Install folium from source
32+
shell: bash -l {0}
33+
run: |
34+
python -m pip install -e . --no-deps --force-reinstall
35+
36+
- name: Test with pytest
37+
shell: bash -l {0}
38+
run: |
39+
python -m pytest tests/snapshots -s --junit-xml=test-results.xml
40+
41+
- name: Surface failing tests
42+
if: always()
43+
uses: pmeier/pytest-results-action@main
44+
with:
45+
path: test-results.xml
46+
fail-on-empty: false
47+
48+
- name: Upload screenshots
49+
if: failure()
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: screenshots
53+
path: |
54+
/tmp/screenshot_*_*.png
55+
/tmp/folium_map_*.html

.github/workflows/test_streamlit_folium.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
shell: bash -l {0}
6767
run: |
6868
cd streamlit_folium
69-
pytest tests/test_frontend.py --browser chromium -s --reruns 3 --junit-xml=test-results.xml
69+
pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" --junit-xml=test-results.xml
7070
7171
- name: Surface failing tests
7272
if: always()

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ repos:
99
- id: debug-statements
1010
- id: end-of-file-fixer
1111
- id: check-docstring-first
12+
exclude: ^examples/streamlit
1213
- id: check-added-large-files
14+
args: ['--maxkb=1024']
1315
- id: requirements-txt-fixer
1416
- id: file-contents-sorter
1517
files: requirements-dev.txt

.streamlit/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[server]
2+
enableStaticServing = true

folium/plugins/search.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from branca.element import MacroElement
22

3+
from folium import FeatureGroup, GeoJson, TopoJson
34
from folium.elements import JSCSSMixin
4-
from folium.features import FeatureGroup, GeoJson, TopoJson
5+
6+
# from folium.map import FeatureGroup
7+
# from folium.features import GeoJson, TopoJson
58
from folium.folium import Map
69
from folium.plugins import MarkerCluster
710
from folium.template import Template

tests/snapshots/modules/issue_1885.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import folium
2+
3+
# Library of Congress coordinates (latitude, longitude)
4+
loc_coordinates = (38.8886, -77.0047)
5+
6+
# Create a Folium map centered around the Library of Congress
7+
m = folium.Map(tiles=None, location=loc_coordinates, zoom_start=15)
8+
9+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
10+
11+
12+
svg = """
13+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="35"
14+
width="35">
15+
<path d="M12
16+
21.5C10.65 20.65 8.2 20 6.5 20C4.85 20 3.15 20.3 1.75 21.05C1.65 21.1 1.6 21.1
17+
1.5 21.1C1.25 21.1 1 20.85 1 20.6V6C1.6 5.55 2.25 5.25 3 5C4.11 4.65 5.33 4.5
18+
6.5 4.5C8.45 4.5 10.55 4.9 12 6C13.45 4.9 15.55 4.5 17.5 4.5C18.67 4.5 19.89
19+
4.65 21 5C21.75 5.25 22.4 5.55 23 6V20.6C23 20.85 22.75 21.1 22.5 21.1C22.4
20+
21.1 22.35 21.1 22.25 21.05C20.85 20.3 19.15 20 17.5 20C15.8 20 13.35 20.65 12
21+
21.5M11 7.5C9.64 6.9 7.84 6.5 6.5 6.5C5.3 6.5 4.1 6.65 3 7V18.5C4.1 18.15 5.3
22+
18 6.5 18C7.84 18 9.64 18.4 11 19V7.5M13 19C14.36 18.4 16.16 18 17.5 18C18.7 18
23+
19.9 18.15 21 18.5V7C19.9 6.65 18.7 6.5 17.5 6.5C16.16 6.5 14.36 6.9 13
24+
7.5V19M14 16.35C14.96 16 16.12 15.83 17.5 15.83C18.54 15.83 19.38 15.91 20
25+
16.07V14.57C19.13 14.41 18.29 14.33 17.5 14.33C16.16 14.33 15 14.5 14
26+
14.76V16.35M14 13.69C14.96 13.34 16.12 13.16 17.5 13.16C18.54 13.16 19.38 13.24
27+
20 13.4V11.9C19.13 11.74 18.29 11.67 17.5 11.67C16.22 11.67 15.05 11.82 14
28+
12.12V13.69M14 11C14.96 10.67 16.12 10.5 17.5 10.5C18.41 10.5 19.26 10.59 20
29+
10.78V9.23C19.13 9.08 18.29 9 17.5 9C16.18 9 15 9.15 14 9.46V11Z"/></svg>"""
30+
31+
icon = folium.DivIcon(
32+
icon_anchor=(15, 15),
33+
html=f"<div>{svg}</div>",
34+
)
35+
36+
37+
folium.Marker(
38+
location=(38.886970844230866, -77.00471380332),
39+
popup="Library of Congress: James Madison Building",
40+
icon=icon,
41+
).add_to(m)
42+
43+
folium.Marker(location=loc_coordinates, popup="Library of Congress", icon=icon).add_to(
44+
m
45+
)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import folium
2+
3+
# Library of Congress coordinates (latitude, longitude)
4+
loc_coordinates = (38.8886, -77.0047)
5+
6+
# Create a Folium map centered around the Library of Congress
7+
m = folium.Map(tiles=None, location=loc_coordinates, zoom_start=15)
8+
9+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
10+
11+
12+
svg = """
13+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="35"
14+
width="35">
15+
<path d="M12
16+
21.5C10.65 20.65 8.2 20 6.5 20C4.85 20 3.15 20.3 1.75 21.05C1.65 21.1 1.6 21.1
17+
1.5 21.1C1.25 21.1 1 20.85 1 20.6V6C1.6 5.55 2.25 5.25 3 5C4.11 4.65 5.33 4.5
18+
6.5 4.5C8.45 4.5 10.55 4.9 12 6C13.45 4.9 15.55 4.5 17.5 4.5C18.67 4.5 19.89
19+
4.65 21 5C21.75 5.25 22.4 5.55 23 6V20.6C23 20.85 22.75 21.1 22.5 21.1C22.4
20+
21.1 22.35 21.1 22.25 21.05C20.85 20.3 19.15 20 17.5 20C15.8 20 13.35 20.65 12
21+
21.5M11 7.5C9.64 6.9 7.84 6.5 6.5 6.5C5.3 6.5 4.1 6.65 3 7V18.5C4.1 18.15 5.3
22+
18 6.5 18C7.84 18 9.64 18.4 11 19V7.5M13 19C14.36 18.4 16.16 18 17.5 18C18.7 18
23+
19.9 18.15 21 18.5V7C19.9 6.65 18.7 6.5 17.5 6.5C16.16 6.5 14.36 6.9 13
24+
7.5V19M14 16.35C14.96 16 16.12 15.83 17.5 15.83C18.54 15.83 19.38 15.91 20
25+
16.07V14.57C19.13 14.41 18.29 14.33 17.5 14.33C16.16 14.33 15 14.5 14
26+
14.76V16.35M14 13.69C14.96 13.34 16.12 13.16 17.5 13.16C18.54 13.16 19.38 13.24
27+
20 13.4V11.9C19.13 11.74 18.29 11.67 17.5 11.67C16.22 11.67 15.05 11.82 14
28+
12.12V13.69M14 11C14.96 10.67 16.12 10.5 17.5 10.5C18.41 10.5 19.26 10.59 20
29+
10.78V9.23C19.13 9.08 18.29 9 17.5 9C16.18 9 15 9.15 14 9.46V11Z"/></svg>"""
30+
31+
icon = folium.DivIcon(
32+
icon_anchor=(15, 15),
33+
html=f"<div>{svg}</div>",
34+
)
35+
36+
37+
m1 = (
38+
folium.Marker(
39+
location=(38.886970844230866, -77.00471380332),
40+
popup="Library of Congress: James Madison Building",
41+
)
42+
.add_child(icon)
43+
.add_to(m)
44+
)
45+
46+
m2 = (
47+
folium.Marker(location=loc_coordinates, popup="Library of Congress")
48+
.add_child(icon)
49+
.add_to(m)
50+
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import folium
2+
3+
# Library of Congress coordinates (latitude, longitude)
4+
loc_coordinates = (38.8886, -77.0047)
5+
6+
# Create a Folium map centered around the Library of Congress
7+
m = folium.Map(tiles=None, location=loc_coordinates, zoom_start=15)
8+
9+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
10+
11+
svg = """
12+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="35"
13+
width="35">
14+
<path d="M12
15+
21.5C10.65 20.65 8.2 20 6.5 20C4.85 20 3.15 20.3 1.75 21.05C1.65 21.1 1.6 21.1
16+
1.5 21.1C1.25 21.1 1 20.85 1 20.6V6C1.6 5.55 2.25 5.25 3 5C4.11 4.65 5.33 4.5
17+
6.5 4.5C8.45 4.5 10.55 4.9 12 6C13.45 4.9 15.55 4.5 17.5 4.5C18.67 4.5 19.89
18+
4.65 21 5C21.75 5.25 22.4 5.55 23 6V20.6C23 20.85 22.75 21.1 22.5 21.1C22.4
19+
21.1 22.35 21.1 22.25 21.05C20.85 20.3 19.15 20 17.5 20C15.8 20 13.35 20.65 12
20+
21.5M11 7.5C9.64 6.9 7.84 6.5 6.5 6.5C5.3 6.5 4.1 6.65 3 7V18.5C4.1 18.15 5.3
21+
18 6.5 18C7.84 18 9.64 18.4 11 19V7.5M13 19C14.36 18.4 16.16 18 17.5 18C18.7 18
22+
19.9 18.15 21 18.5V7C19.9 6.65 18.7 6.5 17.5 6.5C16.16 6.5 14.36 6.9 13
23+
7.5V19M14 16.35C14.96 16 16.12 15.83 17.5 15.83C18.54 15.83 19.38 15.91 20
24+
16.07V14.57C19.13 14.41 18.29 14.33 17.5 14.33C16.16 14.33 15 14.5 14
25+
14.76V16.35M14 13.69C14.96 13.34 16.12 13.16 17.5 13.16C18.54 13.16 19.38 13.24
26+
20 13.4V11.9C19.13 11.74 18.29 11.67 17.5 11.67C16.22 11.67 15.05 11.82 14
27+
12.12V13.69M14 11C14.96 10.67 16.12 10.5 17.5 10.5C18.41 10.5 19.26 10.59 20
28+
10.78V9.23C19.13 9.08 18.29 9 17.5 9C16.18 9 15 9.15 14 9.46V11Z"/></svg>"""
29+
30+
icon = folium.DivIcon(
31+
icon_anchor=(15, 15),
32+
html=f"<div>{svg}</div>",
33+
)
34+
35+
m1 = folium.Marker(
36+
location=(38.886970844230866, -77.00471380332),
37+
popup="Library of Congress: James Madison Building",
38+
).add_to(m)
39+
40+
m2 = folium.Marker(
41+
location=loc_coordinates,
42+
popup="Library of Congress",
43+
).add_to(m)
44+
# if we save here, everything will be fine.
45+
46+
icon.add_to(m1)
47+
icon.add_to(m2)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import folium
2+
3+
# Library of Congress coordinates (latitude, longitude)
4+
loc_coordinates = (38.8886, -77.0047)
5+
6+
# Create a Folium map centered around the Library of Congress
7+
m = folium.Map(tiles=None, location=loc_coordinates, zoom_start=15)
8+
9+
# Define the DivIcon with the custom icon. This variable can be used in one marker successfully, but will fail if we use it in two markers.
10+
11+
12+
svg = """
13+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="35"
14+
width="35">
15+
<path d="M12
16+
21.5C10.65 20.65 8.2 20 6.5 20C4.85 20 3.15 20.3 1.75 21.05C1.65 21.1 1.6 21.1
17+
1.5 21.1C1.25 21.1 1 20.85 1 20.6V6C1.6 5.55 2.25 5.25 3 5C4.11 4.65 5.33 4.5
18+
6.5 4.5C8.45 4.5 10.55 4.9 12 6C13.45 4.9 15.55 4.5 17.5 4.5C18.67 4.5 19.89
19+
4.65 21 5C21.75 5.25 22.4 5.55 23 6V20.6C23 20.85 22.75 21.1 22.5 21.1C22.4
20+
21.1 22.35 21.1 22.25 21.05C20.85 20.3 19.15 20 17.5 20C15.8 20 13.35 20.65 12
21+
21.5M11 7.5C9.64 6.9 7.84 6.5 6.5 6.5C5.3 6.5 4.1 6.65 3 7V18.5C4.1 18.15 5.3
22+
18 6.5 18C7.84 18 9.64 18.4 11 19V7.5M13 19C14.36 18.4 16.16 18 17.5 18C18.7 18
23+
19.9 18.15 21 18.5V7C19.9 6.65 18.7 6.5 17.5 6.5C16.16 6.5 14.36 6.9 13
24+
7.5V19M14 16.35C14.96 16 16.12 15.83 17.5 15.83C18.54 15.83 19.38 15.91 20
25+
16.07V14.57C19.13 14.41 18.29 14.33 17.5 14.33C16.16 14.33 15 14.5 14
26+
14.76V16.35M14 13.69C14.96 13.34 16.12 13.16 17.5 13.16C18.54 13.16 19.38 13.24
27+
20 13.4V11.9C19.13 11.74 18.29 11.67 17.5 11.67C16.22 11.67 15.05 11.82 14
28+
12.12V13.69M14 11C14.96 10.67 16.12 10.5 17.5 10.5C18.41 10.5 19.26 10.59 20
29+
10.78V9.23C19.13 9.08 18.29 9 17.5 9C16.18 9 15 9.15 14 9.46V11Z"/></svg>"""
30+
31+
icon = folium.DivIcon(
32+
icon_anchor=(15, 15),
33+
html=f"<div>{svg}</div>",
34+
)
35+
36+
marker1 = folium.Marker(
37+
location=(38.886970844230866, -77.00471380332),
38+
popup="Library of Congress: James Madison Building",
39+
).add_to(m)
40+
41+
marker2 = folium.Marker(
42+
location=loc_coordinates, popup="Library of Congress", icon=icon
43+
).add_to(m)
44+
45+
marker1.set_icon(icon)
46+
marker2.set_icon(icon)

0 commit comments

Comments
 (0)