Path: blob/main/tests/plugins/test_encoded.py
1601 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(31"""32var {{this.get_name()}} = L.Polyline.fromEncoded(33{{ this.encoded|tojson }},34{{ this.options|tojavascript }}35).addTo({{this._parent.get_name()}});36"""37)3839expected_render = tmpl.render(this=polyline)40actual_render = polyline._template.module.script(polyline)4142assert normalize(expected_render) == normalize(actual_render)434445def test_polygon_from_encoded():46"""Test `PolygonFromEncoded` plugin.4748The test ensures:49- The original JS script is present in the HTML file.50- The rendering from `PolygonFromEncoded` and the original plugin gives the51same output.52"""5354m = Map([40.0, -80.0], zoom_start=3)5556encoded = r"w`j~FpxivO}jz@qnnCd}~Bsa{@~f`C`lkH"57polygon = PolygonFromEncoded(encoded=encoded, kwargs={})5859polygon.add_to(m)6061out = normalize(m._parent.render())6263script = '<script src="https://cdn.jsdelivr.net/npm/[email protected]/Polyline.encoded.js"></script>'64assert script in out6566tmpl = Template(67"""68var {{this.get_name()}} = L.Polygon.fromEncoded(69{{ this.encoded|tojson }},70{{ this.options|tojavascript }}71)72.addTo({{this._parent.get_name()}});73"""74)7576expected_render = tmpl.render(this=polygon)7778actual_render = polygon._template.module.script(polygon)7980assert normalize(expected_render) == normalize(actual_render)818283