Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/plugins/test_boat_marker.py
1601 views
1
"""
2
Test BoatMarker
3
---------------
4
5
"""
6
7
import folium
8
from folium import plugins
9
from folium.template import Template
10
from folium.utilities import normalize
11
12
13
def test_boat_marker():
14
m = folium.Map([30.0, 0.0], zoom_start=3)
15
bm1 = plugins.BoatMarker(
16
(34, -43), heading=45, wind_heading=150, wind_speed=45, color="#8f8"
17
)
18
bm2 = plugins.BoatMarker(
19
(46, -30), heading=-20, wind_heading=46, wind_speed=25, color="#88f"
20
)
21
22
m.add_child(bm1)
23
m.add_child(bm2)
24
m._repr_html_()
25
26
out = normalize(m._parent.render())
27
28
# We verify that the script import is present.
29
script = '<script src="https://unpkg.com/leaflet.boatmarker/leaflet.boatmarker.min.js"></script>' # noqa
30
assert script in out
31
32
# We verify that the script part is correct.
33
tmpl = Template(
34
"""
35
var {{ this.get_name() }} = L.boatMarker(
36
{{ this.location|tojson }},
37
{{ this.options|tojavascript }}
38
).addTo({{ this._parent.get_name() }});
39
{{ this.get_name() }}.setHeadingWind(
40
{{ this.heading }},
41
{{ this.wind_speed }},
42
{{ this.wind_heading }}
43
);
44
"""
45
)
46
47
assert normalize(tmpl.render(this=bm1)) in out
48
assert normalize(tmpl.render(this=bm2)) in out
49
50
bounds = m.get_bounds()
51
assert bounds == [[34, -43], [46, -30]], bounds
52
53
54
def test_boat_marker_with_no_wind_speed_or_heading():
55
m = folium.Map([30.0, 0.0], zoom_start=3)
56
bm1 = plugins.BoatMarker((34, -43), heading=45, color="#8f8")
57
m.add_child(bm1)
58
59
out = normalize(m._parent.render())
60
61
# We verify that the script part is correct.
62
tmpl = Template(
63
"""
64
var {{ this.get_name() }} = L.boatMarker(
65
{{ this.location|tojson }},
66
{{ this.options|tojavascript }}
67
).addTo({{ this._parent.get_name() }});
68
{{ this.get_name() }}.setHeading({{ this.heading }});
69
"""
70
)
71
72
assert normalize(tmpl.render(this=bm1)) in out
73
74