Path: blob/main/tests/plugins/test_realtime.py
1601 views
"""1Test Realtime2------------------3"""45import folium6from folium.plugins import MarkerCluster, Realtime7from folium.template import Template8from folium.utilities import JsCode, normalize91011def test_realtime():12m = folium.Map(location=[40.73, -73.94], zoom_start=12)13source = "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/subway_stations.geojson"1415container = MarkerCluster().add_to(m)1617rt = Realtime(18source,19get_feature_id=JsCode("(f) => { return f.properties.objectid }"),20point_to_layer=JsCode(21"(f, latlng) => { return L.circleMarker(latlng, {radius: 8, fillOpacity: 0.2})}"22),23container=container,24interval=10000,25)26rt.add_to(m)2728tmpl_for_expected = Template(29"""30{% macro script(this, kwargs) %}31var {{ this.get_name() }}_options = {{ this.options|tojavascript }};32{% for key, value in this.functions.items() %}33{{ this.get_name() }}_options["{{key}}"] = {{ value }};34{% endfor %}3536{% if this.container -%}37{{ this.get_name() }}_options["container"]38= {{ this.container.get_name() }};39{% endif -%}4041var {{ this.get_name() }} = new L.realtime(42{% if this.src is string or this.src is mapping -%}43{{ this.src|tojson }},44{% else -%}45{{ this.src.js_code }},46{% endif -%}47{{ this.get_name() }}_options48);49{{ this._parent.get_name() }}.addLayer(50{{ this.get_name() }}._container);51{% endmacro %}52"""53)54expected = normalize(tmpl_for_expected.render(this=rt))5556out = normalize(m._parent.render())5758# We verify that imports59assert (60'<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-realtime/2.2.0/leaflet-realtime.js"></script>' # noqa61in out62) # noqa6364assert expected in out656667