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
2529 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
var {{ this.get_name() }} = L.boatMarker(
35
{{ this.location|tojson }},
36
{{ this.options|tojavascript }}
37
).addTo({{ this._parent.get_name() }});
38
{{ this.get_name() }}.setHeadingWind(
39
{{ this.heading }},
40
{{ this.wind_speed }},
41
{{ this.wind_heading }}
42
);
43
""")
44
45
assert normalize(tmpl.render(this=bm1)) in out
46
assert normalize(tmpl.render(this=bm2)) in out
47
48
bounds = m.get_bounds()
49
assert bounds == [[34, -43], [46, -30]], bounds
50
51
52
def test_boat_marker_with_no_wind_speed_or_heading():
53
m = folium.Map([30.0, 0.0], zoom_start=3)
54
bm1 = plugins.BoatMarker((34, -43), heading=45, color="#8f8")
55
m.add_child(bm1)
56
57
out = normalize(m._parent.render())
58
59
# We verify that the script part is correct.
60
tmpl = Template("""
61
var {{ this.get_name() }} = L.boatMarker(
62
{{ this.location|tojson }},
63
{{ this.options|tojavascript }}
64
).addTo({{ this._parent.get_name() }});
65
{{ this.get_name() }}.setHeading({{ this.heading }});
66
""")
67
68
assert normalize(tmpl.render(this=bm1)) in out
69
70