10
10
11
11
import folium
12
12
from folium .plugins import TimeSliderChoropleth
13
-
13
+ from folium . utilities import normalize
14
14
15
15
import numpy as np
16
16
19
19
import pytest
20
20
21
21
22
- @pytest .mark .xfail
23
22
def test_timedynamic_geo_json ():
24
23
"""
25
24
tests folium.plugins.TimeSliderChoropleth
@@ -29,8 +28,15 @@ def test_timedynamic_geo_json():
29
28
datapath = gpd .datasets .get_path ('naturalearth_lowres' )
30
29
gdf = gpd .read_file (datapath )
31
30
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
+ '''
32
37
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 ]
34
40
35
41
styledata = {}
36
42
@@ -71,12 +77,15 @@ def norm(col):
71
77
rendered = time_slider_choropleth ._template .module .script (time_slider_choropleth )
72
78
73
79
m ._repr_html_ ()
74
- out = m ._parent .render ()
80
+ out = normalize ( m ._parent .render () )
75
81
assert '<script src="https://d3js.org/d3.v4.min.js"></script>' in out
76
82
77
83
# 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