Path: blob/main/tests/plugins/test_polyline_offset.py
1601 views
"""1Test PolyLineOffset2-------------------3"""45import pytest67import folium8from folium import plugins9from folium.utilities import normalize101112@pytest.mark.parametrize("offset", [0, 10, -10])13def test_polylineoffset(offset):14m = folium.Map([20.0, 0.0], zoom_start=3)1516locations = [17[59.355600, -31.99219],18[55.178870, -42.89062],19[47.754100, -43.94531],20[38.272690, -37.96875],21[27.059130, -41.13281],22[16.299050, -36.56250],23[8.4071700, -30.23437],24[1.0546300, -22.50000],25[-8.754790, -18.28125],26[-21.61658, -20.03906],27[-31.35364, -24.25781],28[-39.90974, -30.93750],29[-43.83453, -41.13281],30[-47.75410, -49.92187],31[-50.95843, -54.14062],32[-55.97380, -56.60156],33]3435polylineoffset = plugins.PolyLineOffset(locations=locations, offset=offset)36polylineoffset.add_to(m)3738m._repr_html_()39out = m._parent.render()4041# We verify that the script import is present.42script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/leaflet.polylineoffset.min.js"></script>' # noqa43assert script in out4445# We verify that the script part is correct.46expected_rendered = f"""47var {polylineoffset.get_name()} = L.polyline(48{locations},49{{50"bubblingMouseEvents": true,51"color": "#3388ff",52"dashArray": null,53"dashOffset": null,54"fill": false,55"fillColor": "#3388ff",56"fillOpacity": 0.2,57"fillRule": "evenodd",58"lineCap": "round",59"lineJoin": "round",60"noClip": false,61"offset": {offset},62"opacity": 1.0,63"smoothFactor": 1.0,64"stroke": true,65"weight": 366}}67)68.addTo({m.get_name()});69"""7071rendered = polylineoffset._template.module.script(polylineoffset)72assert normalize(expected_rendered) == normalize(rendered)737475def test_polylineoffset_without_offset():76m = folium.Map([20.0, 0.0], zoom_start=3)7778locations = [[59.355600, -31.99219], [55.178870, -42.89062]]7980polylineoffset = plugins.PolyLineOffset(locations=locations)81polylineoffset.add_to(m)8283m._repr_html_()84out = m._parent.render()8586# We verify that the script import is present.87script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/leaflet.polylineoffset.min.js"></script>' # noqa88assert script in out8990# We verify that the script part is correct.91expected_rendered = f"""92var {polylineoffset.get_name()} = L.polyline(93{locations},94{{95"bubblingMouseEvents": true,96"color": "#3388ff",97"dashArray": null,98"dashOffset": null,99"fill": false,100"fillColor": "#3388ff",101"fillOpacity": 0.2,102"fillRule": "evenodd",103"lineCap": "round",104"lineJoin": "round",105"noClip": false,106"offset": 0,107"opacity": 1.0,108"smoothFactor": 1.0,109"stroke": true,110"weight": 3111}}112)113.addTo({m.get_name()});114"""115116rendered = polylineoffset._template.module.script(polylineoffset)117assert normalize(expected_rendered) == normalize(rendered)118119120