-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Moved plugins test to tests/plugins #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Plugins tests | ||
------------- | ||
|
||
Create at least one test per plugin. | ||
""" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test BoatMarker | ||
--------------- | ||
|
||
""" | ||
from jinja2 import Template | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_boat_marker(): | ||
m = folium.Map([30., 0.], zoom_start=3) | ||
bm1 = plugins.BoatMarker( | ||
(34, -43), | ||
heading=45, | ||
wind_heading=150, | ||
wind_speed=45, | ||
color="#8f8") | ||
bm2 = plugins.BoatMarker( | ||
(46, -30), | ||
heading=-20, | ||
wind_heading=46, | ||
wind_speed=25, | ||
color="#88f") | ||
|
||
m.add_children(bm1) | ||
m.add_children(bm2) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# We verify that the script import is present | ||
assert ('<script src="https://thomasbrueggemann.github.io/leaflet.boatmarker/' | ||
'js/leaflet.boatmarker.min.js"></script>' | ||
) in out | ||
|
||
# We verify that the script part is correct | ||
tmpl = Template(""" | ||
var {{this.get_name()}} = L.boatMarker( | ||
[{{this.position[0]}},{{this.position[1]}}], | ||
{{this.kwargs}}).addTo({{this._parent.get_name()}}); | ||
{{this.get_name()}}.setHeadingWind({{this.heading}}, {{this.wind_speed}}, {{this.wind_heading}}); | ||
""") | ||
|
||
assert tmpl.render(this=bm1) in out | ||
assert tmpl.render(this=bm2) in out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test HeatMap | ||
------------ | ||
""" | ||
|
||
from jinja2 import Template | ||
import numpy as np | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_heat_map(): | ||
data = (np.random.normal(size=(100, 2)) * np.array([[1, 1]]) + | ||
np.array([[48, 5]])).tolist() | ||
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6) | ||
hm = plugins.HeatMap(data) | ||
m.add_children(hm) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# We verify that the script import is present | ||
assert ('<script src="https://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js"></script>' | ||
) in out | ||
# We verify that the script part is correct | ||
tmpl = Template(""" | ||
var {{this.get_name()}} = L.heatLayer( | ||
{{this.data}}, | ||
{ | ||
minOpacity: {{this.min_opacity}}, | ||
maxZoom: {{this.max_zoom}}, | ||
max: {{this.max_val}}, | ||
radius: {{this.radius}}, | ||
blur: {{this.blur}}, | ||
gradient: {{this.gradient}} | ||
}) | ||
.addTo({{this._parent.get_name()}}); | ||
""") | ||
|
||
assert tmpl.render(this=hm) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test ImageOverlay | ||
----------------- | ||
|
||
""" | ||
|
||
from jinja2 import Template | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_image_overlay(): | ||
"""Test image overlay.""" | ||
data = [[[1, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]], | ||
[[1, 1, 0, 0.5], [0, 0, 1, 1], [0, 0, 1, 1]]] | ||
|
||
m = folium.Map() | ||
io = plugins.ImageOverlay(data, [[0, -180], [90, 180]], mercator_project=True) | ||
io.add_to(m) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# Verify the url generation | ||
assert io.url == ('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAA' | ||
'AF0lEQVR42mP4z8AARFDw/z/DeiA5H4QBV60H6ABl9ZIAAAAASUVORK5CYII=') | ||
|
||
# Verify the script part is okay. | ||
tmpl = Template(""" | ||
var {{this.get_name()}} = L.imageOverlay( | ||
'{{ this.url }}', | ||
{{ this.bounds }}, | ||
{{ this.options }} | ||
).addTo({{this._parent.get_name()}}); | ||
""") | ||
assert tmpl.render(this=io) in out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test MarkerCluster | ||
------------------ | ||
""" | ||
|
||
from jinja2 import Template | ||
import numpy as np | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_marker_cluster(): | ||
N = 100 | ||
data = np.array([ | ||
np.random.uniform(low=35, high=60, size=N), # Random latitudes. | ||
np.random.uniform(low=-12, high=30, size=N), # Random longitudes. | ||
range(N), # Popups. | ||
]).T | ||
m = folium.Map([45., 3.], zoom_start=4) | ||
mc = plugins.MarkerCluster(data) | ||
m.add_children(mc) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# We verify that imports | ||
assert ('<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.' | ||
'markercluster/0.4.0/leaflet.markercluster.js"></script>') in out | ||
assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/' | ||
'libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />') in out | ||
assert ('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/' | ||
'libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />' | ||
) in out | ||
|
||
# Verify the script part is okay. | ||
tmpl = Template(""" | ||
var {{this.get_name()}} = L.markerClusterGroup(); | ||
{{this._parent.get_name()}}.addLayer({{this.get_name()}}); | ||
|
||
{% for marker in this._children.values() %} | ||
var {{marker.get_name()}} = L.marker( | ||
[{{marker.location[0]}},{{marker.location[1]}}], | ||
{ | ||
icon: new L.Icon.Default() | ||
} | ||
) | ||
.addTo({{this.get_name()}}); | ||
{% endfor %} | ||
""") | ||
assert ''.join(tmpl.render(this=mc).split()) in ''.join(out.split()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test ScrollZoomToggler | ||
---------------------- | ||
""" | ||
|
||
from jinja2 import Template | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_scroll_zoom_toggler(): | ||
m = folium.Map([45., 3.], zoom_start=4) | ||
szt = plugins.ScrollZoomToggler() | ||
m.add_children(szt) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# Verify that the div has been created. | ||
tmpl = Template(""" | ||
<img id="{{this.get_name()}}" alt="scroll" | ||
src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/1.5.2/png/512/arrow-move.png" | ||
onclick="{{this._parent.get_name()}}.toggleScroll()"></img> | ||
""") | ||
assert ''.join(tmpl.render(this=szt).split()) in ''.join(out.split()) | ||
|
||
# Verify that the style has been created | ||
tmpl = Template(""" | ||
<style> | ||
#{{this.get_name()}} { | ||
position:absolute; | ||
width:35px; | ||
bottom:10px; | ||
height:35px; | ||
left:10px; | ||
background-color:#fff; | ||
text-align:center; | ||
line-height:35px; | ||
vertical-align: middle; | ||
} | ||
</style> | ||
""") | ||
assert ''.join(tmpl.render(this=szt).split()) in ''.join(out.split()) | ||
|
||
# Verify that the script is okay. | ||
tmpl = Template(""" | ||
{{this._parent.get_name()}}.scrollEnabled = true; | ||
|
||
{{this._parent.get_name()}}.toggleScroll = function() { | ||
if (this.scrollEnabled) { | ||
this.scrollEnabled = false; | ||
this.scrollWheelZoom.disable(); | ||
} | ||
else { | ||
this.scrollEnabled = true; | ||
this.scrollWheelZoom.enable(); | ||
} | ||
}; | ||
|
||
{{this._parent.get_name()}}.toggleScroll(); | ||
""") | ||
assert ''.join(tmpl.render(this=szt).split()) in ''.join(out.split()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Test Terminator | ||
--------------- | ||
""" | ||
|
||
from jinja2 import Template | ||
|
||
import folium | ||
from folium import plugins | ||
|
||
def test_terminator(): | ||
m = folium.Map([45., 3.], zoom_start=1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Virtually all tests start by importing, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be okay, but I would keep it for another PR (maybe At the cost of doing this, I'd like to have an object like
but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a plan. Can I merge it then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appart from this, I've applied you comments (spaces), and rebased. |
||
t = plugins.Terminator() | ||
m.add_children(t) | ||
m._repr_html_() | ||
|
||
out = m._parent.render() | ||
|
||
# Verify that the script is okay. | ||
tmpl = Template('L.terminator().addTo({{this._parent.get_name()}});') | ||
assert ''.join(tmpl.render(this=t).split()) in ''.join(out.split()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that the tests found this bug 😜