1010
1111import folium
1212from folium .plugins import TimeSliderChoropleth
13-
13+ from folium . utilities import normalize
1414
1515import numpy as np
1616
1919import pytest
2020
2121
22- @pytest .mark .xfail
2322def test_timedynamic_geo_json ():
2423 """
2524 tests folium.plugins.TimeSliderChoropleth
@@ -29,8 +28,15 @@ def test_timedynamic_geo_json():
2928 datapath = gpd .datasets .get_path ('naturalearth_lowres' )
3029 gdf = gpd .read_file (datapath )
3130
31+ '''
32+ Timestamps, start date is carefully chosen to be earlier than 2001-09-09
33+ (9 digit timestamp), end date is later (10 digits). This is to ensure an
34+ integer sort is used (and not a string sort were '2' > '10').
35+ datetime.strftime('%s') on Windows just generates date and not timestamp so avoid.
36+ '''
3237 n_periods = 3
33- dt_index = pd .date_range ('2016-1-1' , periods = n_periods , freq = 'M' ).strftime ('%s' )
38+ dt_range = pd .Series (pd .date_range ('2001-08-1' , periods = n_periods , freq = 'M' ))
39+ dt_index = [f"{ dt .timestamp ():.0f} " for dt in dt_range ]
3440
3541 styledata = {}
3642
@@ -71,12 +77,15 @@ def norm(col):
7177 rendered = time_slider_choropleth ._template .module .script (time_slider_choropleth )
7278
7379 m ._repr_html_ ()
74- out = m ._parent .render ()
80+ out = normalize ( m ._parent .render () )
7581 assert '<script src="https://d3js.org/d3.v4.min.js"></script>' in out
7682
7783 # We verify that data has been inserted correctly
78- expected_timestamps = """var timestamps = ["1454198400", "1456704000", "1459382400"];""" # noqa
79- assert expected_timestamps .split (';' )[0 ].strip () == rendered .split (';' )[0 ].strip ()
80-
81- expected_styledict = json .dumps (styledict , sort_keys = True , indent = 2 )
82- assert expected_styledict in rendered
84+ expected_timestamps = sorted (dt_index , key = int ) # numeric sort
85+ expected_timestamps = "var timestamps = {};" .format (expected_timestamps )
86+ expected_timestamps = expected_timestamps .split (';' )[0 ].strip ().replace ("'" , '"' )
87+ rendered_timestamps = rendered .split (';' )[0 ].strip ()
88+ assert expected_timestamps == rendered_timestamps
89+
90+ expected_styledict = normalize (json .dumps (styledict , sort_keys = True ))
91+ assert expected_styledict in normalize (rendered )
0 commit comments