Skip to content

Commit b0120e8

Browse files
committed
Fixes #341: Added Highlight Test
1 parent e25111c commit b0120e8

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

tests/test_folium.py

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

459459
# Verify the geo_json object.
460460
obj_temp = jinja2.Template("""
461-
var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
462-
.addTo({{ this._parent.get_name() }});
461+
var {{ this.get_name() }} = L.geoJson({{ this.style_data() }})
462+
.addTo({{ this._parent.get_name() }});
463463
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
464464
""") # noqa
465465
obj = obj_temp.render(this=geo_json, json=json)
466+
rendered_obj = ''.join(obj.split())[:-1]
467+
466468
assert ''.join(obj.split())[:-1] in out
467469

468470
bounds = self.map.get_bounds()
469471
assert bounds == [[18.948267, -171.742517],
470472
[71.285909, -66.979601]], bounds
471473

474+
def test_geo_json_highlight(self):
475+
# Highlight data binding
476+
self.map = folium.Map([43, -100], zoom_start=4)
477+
path = os.path.join(rootpath, 'us-counties.json')
478+
479+
data = json.load(open(path))
480+
481+
for feature in data['features']:
482+
feature.setdefault('properties', {}).setdefault('style', {}).update({ # noqa
483+
'color': 'black',
484+
'opacity': 1,
485+
'fillOpacity': 0.6,
486+
'weight': 1,
487+
'fillColor': 'blue',
488+
})
489+
490+
self.map.geo_json(geo_str=json.dumps(data), highlight=True)
491+
492+
geo_json = [x for x in self.map._children.values() if
493+
isinstance(x, GeoJson)][0]
494+
495+
out = ''.join(self.map._parent.render().split())
496+
497+
# Verify the geo_json object
498+
obj_temp = jinja2.Template("""
499+
var {{ this.get_name() }} = L.geoJson(
500+
{{ this.style_data() }}
501+
,{onEachFeature: {{this.get_name()}}_onEachFeature }
502+
).addTo({{ this._parent.get_name() }});
503+
{{ this.get_name() }}.setStyle(function(feature) {return feature.properties.style;});
504+
""")
505+
obj = obj_temp.render(this=geo_json, json=json)
506+
rendered_obj = ''.join(obj.split())[:-1]
507+
508+
assert ''.join(obj.split())[:-1] in out
509+
510+
bounds = self.map.get_bounds()
511+
assert bounds == [[18.948267, -171.742517],
512+
[71.285909, -66.979601]], bounds
513+
514+
472515
def test_geo_json_bad_color(self):
473516
"""Test geojson method."""
474517

0 commit comments

Comments
 (0)