Path: blob/main/tests/plugins/test_encoded.py
2532 views
"""Test PolyLineFromEncoded Plugin."""12from folium import Map3from folium.plugins import PolygonFromEncoded, PolyLineFromEncoded4from folium.template import Template5from folium.utilities import normalize678def test_polyline_from_encoded():9"""Test `PolyLineFromEncoded` plugin.1011The test ensures:12- The original JS script is present in the HTML file.13- The rendering from `PolyLineFromEncoded` and the original plugin gives the14same output.15"""1617m = Map([35.0, -120.0], zoom_start=3)1819encoded = r"_p~iF~cn~U_ulLn{vA_mqNvxq`@"20kwargs = {"color": "green"}21polyline = PolyLineFromEncoded(encoded=encoded, **kwargs)2223polyline.add_to(m)2425out = normalize(m._parent.render())2627script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/Polyline.encoded.js"></script>'28assert script in out2930tmpl = Template("""31var {{this.get_name()}} = L.Polyline.fromEncoded(32{{ this.encoded|tojson }},33{{ this.options|tojavascript }}34).addTo({{this._parent.get_name()}});35""")3637expected_render = tmpl.render(this=polyline)38actual_render = polyline._template.module.script(polyline)3940assert normalize(expected_render) == normalize(actual_render)414243def test_polygon_from_encoded():44"""Test `PolygonFromEncoded` plugin.4546The test ensures:47- The original JS script is present in the HTML file.48- The rendering from `PolygonFromEncoded` and the original plugin gives the49same output.50"""5152m = Map([40.0, -80.0], zoom_start=3)5354encoded = r"w`j~FpxivO}jz@qnnCd}~Bsa{@~f`C`lkH"55polygon = PolygonFromEncoded(encoded=encoded, kwargs={})5657polygon.add_to(m)5859out = normalize(m._parent.render())6061script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/Polyline.encoded.js"></script>'62assert script in out6364tmpl = Template("""65var {{this.get_name()}} = L.Polygon.fromEncoded(66{{ this.encoded|tojson }},67{{ this.options|tojavascript }}68)69.addTo({{this._parent.get_name()}});70""")7172expected_render = tmpl.render(this=polygon)7374actual_render = polygon._template.module.script(polygon)7576assert normalize(expected_render) == normalize(actual_render)777879