Skip to content

Commit 2498f61

Browse files
committed
adapt the tests
1 parent 4e86777 commit 2498f61

File tree

4 files changed

+117
-101
lines changed

4 files changed

+117
-101
lines changed

tests/plugins/test_image_overlay.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/test_features.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,6 @@ def test_divicon():
9292
assert div.html == html
9393

9494

95-
# WmsTileLayer.
96-
def test_wms_service():
97-
m = Map([40, -100], zoom_start=4)
98-
url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
99-
w = folium.WmsTileLayer(url,
100-
name='test',
101-
fmt='image/png',
102-
layers='nexrad-n0r-900913',
103-
attr=u'Weather data © 2012 IEM Nexrad',
104-
transparent=True)
105-
w.add_to(m)
106-
m._repr_html_()
107-
108-
bounds = m.get_bounds()
109-
assert bounds == [[None, None], [None, None]], bounds
110-
111-
11295
# ColorLine.
11396
def test_color_line():
11497
m = Map([22.5, 22.5], zoom_start=3)

tests/test_folium.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,6 @@ def test_custom_tile(self):
162162
bounds = m.get_bounds()
163163
assert bounds == [[None, None], [None, None]], bounds
164164

165-
def test_custom_tile_subdomains(self):
166-
"""Test custom tile subdomains."""
167-
168-
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
169-
m = folium.Map(location=[45.52, -122.67], tiles=url,
170-
attr='attribution',
171-
subdomains='1234')
172-
173-
url_with_name = 'http://{s}.custom_tiles-subdomains.org/{z}/{x}/{y}.png' # noqa
174-
tile_layer = folium.TileLayer(url,
175-
name='subdomains2',
176-
attr='attribution',
177-
subdomains='5678')
178-
m.add_child(tile_layer)
179-
m.add_tile_layer(tiles=url_with_name, attr='attribution',
180-
subdomains='9012')
181-
182-
out = m._parent.render()
183-
assert '1234' in out
184-
assert '5678' in out
185-
assert '9012' in out
186165

187166
def test_feature_group(self):
188167
"""Test FeatureGroup."""
@@ -334,21 +313,6 @@ def test_custom_icon(self):
334313
bounds = self.m.get_bounds()
335314
assert bounds == [[45, -100], [45, -100]], bounds
336315

337-
def test_tile_layer(self):
338-
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
339-
layer = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
340-
m.add_child(folium.TileLayer(layer, name='OpenStreetMap',
341-
attr='attribution'))
342-
m.add_child(folium.TileLayer(layer,
343-
name='OpenStreetMap2',
344-
attr='attribution2',
345-
overlay=True))
346-
m.add_child(folium.LayerControl())
347-
m._repr_html_()
348-
349-
bounds = m.get_bounds()
350-
assert bounds == [[None, None], [None, None]], bounds
351-
352316
def test_global_switches(self):
353317
m = folium.Map(prefer_canvas=True)
354318
assert (m.global_switches.prefer_canvas is True and

tests/test_raster_layers.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
Test ImageOverlay
5+
-----------------
6+
7+
"""
8+
9+
from __future__ import (absolute_import, division, print_function)
10+
11+
import folium
12+
13+
from jinja2 import Template
14+
15+
16+
def test_tile_layer():
17+
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
18+
layer = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
19+
20+
folium.raster_layers.TileLayer(
21+
tiles=layer,
22+
name='OpenStreetMap',
23+
attr='attribution'
24+
).add_to(m)
25+
26+
folium.raster_layers.TileLayer(
27+
tiles=layer,
28+
name='OpenStreetMap2',
29+
attr='attribution2',
30+
overlay=True).add_to(m)
31+
32+
folium.LayerControl().add_to(m)
33+
m._repr_html_()
34+
35+
bounds = m.get_bounds()
36+
assert bounds == [[None, None], [None, None]], bounds
37+
38+
39+
def test_custom_tile_subdomains():
40+
"""Test custom tile subdomains."""
41+
42+
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
43+
m = folium.Map(location=[45.52, -122.67], tiles=url,
44+
attr='attribution',
45+
subdomains='1234')
46+
47+
url_with_name = 'http://{s}.custom_tiles-subdomains.org/{z}/{x}/{y}.png'
48+
tile_layer = folium.raster_layers.TileLayer(
49+
tiles=url,
50+
name='subdomains2',
51+
attr='attribution',
52+
subdomains='5678'
53+
)
54+
tile_layer.add_to(m)
55+
56+
m.add_tile_layer(
57+
tiles=url_with_name, attr='attribution',
58+
subdomains='9012'
59+
)
60+
61+
out = m._parent.render()
62+
assert '1234' in out
63+
assert '5678' in out
64+
assert '9012' in out
65+
66+
67+
def test_wms():
68+
m = folium.Map([40, -100], zoom_start=4)
69+
url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
70+
w = folium.raster_layers.WmsTileLayer(
71+
url=url,
72+
name='test',
73+
fmt='image/png',
74+
layers='nexrad-n0r-900913',
75+
attr=u'Weather data © 2012 IEM Nexrad',
76+
transparent=True
77+
)
78+
w.add_to(m)
79+
m._repr_html_()
80+
81+
bounds = m.get_bounds()
82+
assert bounds == [[None, None], [None, None]], bounds
83+
84+
85+
def test_image_overlay():
86+
"""Test image overlay."""
87+
data = [[[1, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]],
88+
[[1, 1, 0, 0.5], [0, 0, 1, 1], [0, 0, 1, 1]]]
89+
90+
m = folium.Map()
91+
io = folium.raster_layers.ImageOverlay(
92+
data, [[0, -180], [90, 180]],
93+
mercator_project=True
94+
)
95+
io.add_to(m)
96+
m._repr_html_()
97+
98+
out = m._parent.render()
99+
100+
# Verify the URL generation.
101+
url = ('data:image/png;base64,'
102+
'iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAYAAACddGYaAAA'
103+
'AF0lEQVR42mP4z8AARFDw/z/DeiA5H4QBV60H6ABl9ZIAAAAASUVORK5CYII=')
104+
assert io.url == url
105+
106+
# Verify the script part is okay.
107+
tmpl = Template("""
108+
var {{this.get_name()}} = L.imageOverlay(
109+
'{{ this.url }}',
110+
{{ this.bounds }},
111+
{{ this.options }}
112+
).addTo({{this._parent.get_name()}});
113+
""")
114+
assert tmpl.render(this=io) in out
115+
116+
bounds = m.get_bounds()
117+
assert bounds == [[0, -180], [90, 180]], bounds

0 commit comments

Comments
 (0)