Skip to content

Commit c6c9f04

Browse files
committed
Fixes #341: Added Highlight Test
1 parent 65661de commit c6c9f04

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

tests/test_folium.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,60 @@ def test_geo_json_str(self):
370370

371371
# Verify the geo_json object
372372
obj_temp = jinja2.Template("""
373-
var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
374-
.addTo({{ this._parent.get_name() }});
373+
var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
374+
.addTo({{ this._parent.get_name() }});
375375
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
376376
""")
377377
obj = obj_temp.render(this=geo_json, json=json)
378+
rendered_obj = ''.join(obj.split())[:-1]
379+
378380
assert ''.join(obj.split())[:-1] in out
379381

380382
bounds = self.map.get_bounds()
381383
assert bounds == [[18.948267, -171.742517],
382384
[71.285909, -66.979601]], bounds
383385

386+
def test_geo_json_highlight(self):
387+
# Highlight data binding
388+
self.map = folium.Map([43, -100], zoom_start=4)
389+
path = os.path.join(rootpath, 'us-counties.json')
390+
391+
data = json.load(open(path))
392+
393+
for feature in data['features']:
394+
feature.setdefault('properties', {}).setdefault('style', {}).update({ # noqa
395+
'color': 'black',
396+
'opacity': 1,
397+
'fillOpacity': 0.6,
398+
'weight': 1,
399+
'fillColor': 'blue',
400+
})
401+
402+
self.map.geo_json(geo_str=json.dumps(data), highlight=True)
403+
404+
geo_json = [x for x in self.map._children.values() if
405+
isinstance(x, GeoJson)][0]
406+
407+
out = ''.join(self.map._parent.render().split())
408+
409+
# Verify the geo_json object
410+
obj_temp = jinja2.Template("""
411+
var {{ this.get_name() }} = L.geoJson(
412+
{{ this.style_data() }}
413+
,{onEachFeature: {{this.get_name()}}_onEachFeature }
414+
).addTo({{ this._parent.get_name() }});
415+
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
416+
""")
417+
obj = obj_temp.render(this=geo_json, json=json)
418+
rendered_obj = ''.join(obj.split())[:-1]
419+
420+
assert ''.join(obj.split())[:-1] in out
421+
422+
bounds = self.map.get_bounds()
423+
assert bounds == [[18.948267, -171.742517],
424+
[71.285909, -66.979601]], bounds
425+
426+
384427
def test_geo_json_bad_color(self):
385428
"""Test geojson method."""
386429

0 commit comments

Comments
 (0)