Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_polyline_offset.py
1601 views
1
"""
2
Test PolyLineOffset
3
-------------------
4
"""
5
6
import pytest
7
8
import folium
9
from folium import plugins
10
from folium.utilities import normalize
11
12
13
@pytest.mark.parametrize("offset", [0, 10, -10])
14
def test_polylineoffset(offset):
15
m = folium.Map([20.0, 0.0], zoom_start=3)
16
17
locations = [
18
[59.355600, -31.99219],
19
[55.178870, -42.89062],
20
[47.754100, -43.94531],
21
[38.272690, -37.96875],
22
[27.059130, -41.13281],
23
[16.299050, -36.56250],
24
[8.4071700, -30.23437],
25
[1.0546300, -22.50000],
26
[-8.754790, -18.28125],
27
[-21.61658, -20.03906],
28
[-31.35364, -24.25781],
29
[-39.90974, -30.93750],
30
[-43.83453, -41.13281],
31
[-47.75410, -49.92187],
32
[-50.95843, -54.14062],
33
[-55.97380, -56.60156],
34
]
35
36
polylineoffset = plugins.PolyLineOffset(locations=locations, offset=offset)
37
polylineoffset.add_to(m)
38
39
m._repr_html_()
40
out = m._parent.render()
41
42
# We verify that the script import is present.
43
script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/leaflet.polylineoffset.min.js"></script>' # noqa
44
assert script in out
45
46
# We verify that the script part is correct.
47
expected_rendered = f"""
48
var {polylineoffset.get_name()} = L.polyline(
49
{locations},
50
{{
51
"bubblingMouseEvents": true,
52
"color": "#3388ff",
53
"dashArray": null,
54
"dashOffset": null,
55
"fill": false,
56
"fillColor": "#3388ff",
57
"fillOpacity": 0.2,
58
"fillRule": "evenodd",
59
"lineCap": "round",
60
"lineJoin": "round",
61
"noClip": false,
62
"offset": {offset},
63
"opacity": 1.0,
64
"smoothFactor": 1.0,
65
"stroke": true,
66
"weight": 3
67
}}
68
)
69
.addTo({m.get_name()});
70
"""
71
72
rendered = polylineoffset._template.module.script(polylineoffset)
73
assert normalize(expected_rendered) == normalize(rendered)
74
75
76
def test_polylineoffset_without_offset():
77
m = folium.Map([20.0, 0.0], zoom_start=3)
78
79
locations = [[59.355600, -31.99219], [55.178870, -42.89062]]
80
81
polylineoffset = plugins.PolyLineOffset(locations=locations)
82
polylineoffset.add_to(m)
83
84
m._repr_html_()
85
out = m._parent.render()
86
87
# We verify that the script import is present.
88
script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/leaflet.polylineoffset.min.js"></script>' # noqa
89
assert script in out
90
91
# We verify that the script part is correct.
92
expected_rendered = f"""
93
var {polylineoffset.get_name()} = L.polyline(
94
{locations},
95
{{
96
"bubblingMouseEvents": true,
97
"color": "#3388ff",
98
"dashArray": null,
99
"dashOffset": null,
100
"fill": false,
101
"fillColor": "#3388ff",
102
"fillOpacity": 0.2,
103
"fillRule": "evenodd",
104
"lineCap": "round",
105
"lineJoin": "round",
106
"noClip": false,
107
"offset": 0,
108
"opacity": 1.0,
109
"smoothFactor": 1.0,
110
"stroke": true,
111
"weight": 3
112
}}
113
)
114
.addTo({m.get_name()});
115
"""
116
117
rendered = polylineoffset._template.module.script(polylineoffset)
118
assert normalize(expected_rendered) == normalize(rendered)
119
120