2
2
import json
3
3
import pytest
4
4
import unittest
5
+ import math
5
6
import numpy as np
6
7
from collections import OrderedDict
7
8
@@ -50,7 +51,11 @@ def test_setup_map():
50
51
'zoom_start' : 17 ,
51
52
'width' : 960 ,
52
53
'height' : 500 ,
53
- 'features' : np .array ([1 , 2 , 3 ]), # Pass a NumPy array as features
54
+ 'features' : np .array ([
55
+ ds .Marker (51.514 , - 0.132 ),
56
+ ds .Marker (51.514 , - 0.139 ),
57
+ ds .Marker (51.519 , - 0.132 )
58
+ ]),
54
59
}
55
60
ds .Map (** kwargs1 ).show ()
56
61
ds .Map (** kwargs2 ).show ()
@@ -119,7 +124,40 @@ def test_marker_map_table():
119
124
ds .Marker .map_table (t ).show ()
120
125
colors = ['red' , 'green' , 'yellow' ]
121
126
t ['colors' ] = colors
122
- ds .Marker .map_table (t ).show ()
127
+ markers = ds .Marker .map_table (t )
128
+
129
+ assert markers [0 ]._attrs ['color' ], 'red'
130
+ assert markers [1 ]._attrs ['color' ], 'green'
131
+ assert markers [2 ]._attrs ['color' ], 'yellow'
132
+
133
+ assert markers [0 ].lat_lon [0 ], 51
134
+ assert markers [1 ].lat_lon [0 ], 52
135
+ assert markers [2 ].lat_lon [0 ], 53
136
+
137
+ assert markers [0 ].lat_lon [1 ], - 1
138
+ assert markers [1 ].lat_lon [1 ], - 2
139
+ assert markers [2 ].lat_lon [1 ], - 3
140
+
141
+ def test_circle_map_table ():
142
+ lat_init , lon_init , area_init , color_scale_init = 51 , - 8 , 10 , 10
143
+ lats , lons , areas , color_scales = [], [], [], []
144
+ for i in range (8 ):
145
+ lats .append (lat_init + i )
146
+ lons .append (lon_init + i )
147
+ areas .append ((area_init + 10 * i )** 2 * math .pi )
148
+ color_scales .append (color_scale_init + 10 * i )
149
+ color_scales [- 1 ] = 1000000
150
+ labels = ['A' , 'B' , 'C' ]
151
+ t = ds .Table ().with_columns ('A' , lats , 'B' , lons , 'areas' , areas , 'color_scale' , color_scales )
152
+ markers = ds .Circle .map_table (t , include_color_scale_outliers = False )
153
+
154
+ for i in range (8 ):
155
+ assert markers [i ]._attrs ['radius' ], 10 + 10 * i
156
+
157
+ # Call the map_table method and check if percentiles and outliers are calculated correctly
158
+ assert markers ._attrs ['colorbar_scale' ], [10.0 , 23.125 , 36.25 , 49.375 , 62.5 , 75.625 , 88.75 , 101.875 , 115.0 ]
159
+
160
+ assert [markers [i ]._attrs ['color' ] for i in range (8 )], ['#340597' , '#340597' , '#7008a5' , '#a32494' , '#cf5073' , '#cf5073' , '#ee7c4c' , '#f4e82d' ]
123
161
124
162
125
163
def test_circle_html ():
@@ -143,42 +181,25 @@ def test_marker_copy():
143
181
assert lat == b_lat_lon [0 ]
144
182
assert lon == b_lat_lon [1 ]
145
183
146
- def test_autozoom_value_error ():
147
- """Tests the _autozoom function when ValueError is raised"""
148
- map_obj = ds .Map ()
149
- map_obj ._bounds = {
150
- 'min_lat' : 'invalid' ,
151
- 'max_lat' : 'invalid' ,
152
- 'min_lon' : 'invalid' ,
153
- 'max_lon' : 'invalid'
154
- }
155
- map_obj ._width = 1000
156
- map_obj ._default_zoom = 10
157
-
158
- # Check if ValueError is raised
159
- with pytest .raises (Exception ) as e :
160
- map_obj ._autozoom ()
161
- assert str (e .value ) == 'Check that your locations are lat-lon pairs'
162
-
163
184
def test_background_color_condition_white ():
164
185
# Test the condition when the background color is white (all 'f' in the hex code)
165
186
marker = ds .Marker (0 , 0 , color = '#ffffff' )
166
- assert marker ._folium_kwargs ['icon' ][ 'text_color ' ], 'gray'
187
+ assert marker ._folium_kwargs ['icon' ]. options [ 'textColor ' ], 'gray'
167
188
168
189
def test_background_color_condition_not_white ():
169
190
# Test the condition when the background color is not white
170
191
marker = ds .Marker (0 , 0 , color = '#ff0000' )
171
- assert marker ._folium_kwargs ['icon' ][ 'text_color ' ], 'white'
192
+ assert marker ._folium_kwargs ['icon' ]. options [ 'textColor ' ], 'white'
172
193
173
194
def test_icon_args_icon_not_present ():
174
195
# Test when 'icon' key is not present in icon_args
175
196
marker = ds .Marker (0 , 0 , color = 'blue' , marker_icon = 'info-sign' )
176
- assert marker ._folium_kwargs ['icon' ]['icon' ], 'circle'
197
+ assert marker ._folium_kwargs ['icon' ]. options ['icon' ], 'circle'
177
198
178
199
def test_icon_args_icon_present ():
179
200
# Test when 'icon' key is already present in icon_args
180
201
marker = ds .Marker (0 , 0 , color = 'blue' , marker_icon = 'info-sign' , icon = 'custom-icon' )
181
- assert marker ._folium_kwargs ['icon' ]['icon' ], 'info-sign'
202
+ assert marker ._folium_kwargs ['icon' ]. options ['icon' ], 'info-sign'
182
203
183
204
184
205
def test_geojson ():
@@ -222,50 +243,36 @@ def test_convert_point_no_name():
222
243
}
223
244
converted_marker = ds .Marker ._convert_point (feature )
224
245
assert converted_marker .lat_lon , (54.32 , 98.76 )
225
- assert converted_marker ._attrs ['popup' ], ''
226
-
227
- def test_areas_line ():
228
- # Create a list of dictionaries to represent the table data
229
- data = [
230
- {"latitudes" : 1 , "longitudes" : 4 , "areas" : 10 },
231
- {"latitudes" : 2 , "longitudes" : 5 , "areas" : 20 },
232
- {"latitudes" : 3 , "longitudes" : 6 , "areas" : 30 },
233
- ]
234
-
235
- # Call the map_table method and check if areas are correctly assigned
236
- markers = ds .Marker .map_table (data )
237
- assert markers [0 ].areas , 10
238
- assert markers [1 ].areas , 20
239
- assert markers [2 ].areas , 30
240
-
241
- def test_percentile_and_outlier_lines ():
242
- # Create a list of dictionaries to represent the table data
243
- data = [
244
- {"latitudes" : 1 , "longitudes" : 4 , "color_scale" : 10 },
245
- {"latitudes" : 2 , "longitudes" : 5 , "color_scale" : 20 },
246
- {"latitudes" : 3 , "longitudes" : 6 , "color_scale" : 30 },
247
- ]
248
-
249
- # Call the map_table method and check if percentiles and outliers are calculated correctly
250
- markers = ds .Marker .map_table (data , include_color_scale_outliers = False )
251
- assert markers [0 ].colorbar_scale , [10 , 20 , 30 ]
252
- assert markers [0 ].outlier_min_bound , 10
253
- assert markers [0 ].outlier_max_bound , 30
254
-
255
- def test_return_colors ():
256
- # Create a list of dictionaries to represent the table data
257
- data = [
258
- {"latitudes" : 1 , "longitudes" : 4 , "color_scale" : 10 },
259
- {"latitudes" : 2 , "longitudes" : 5 , "color_scale" : 20 },
260
- {"latitudes" : 3 , "longitudes" : 6 , "color_scale" : 30 },
261
- ]
262
-
263
- # Call the map_table method
264
- markers = ds .Marker .map_table (data , include_color_scale_outliers = False )
265
-
266
- # Call the interpolate_color method with a value that should use the last color
267
- last_color = markers [0 ].interpolate_color (["#340597" , "#7008a5" , "#a32494" ], [10 , 20 ], 25 )
268
- assert last_color , "#a32494"
246
+ assert not converted_marker ._attrs ['popup' ]
247
+
248
+ # def test_percentile_and_outlier_lines():
249
+ # # Create a list of dictionaries to represent the table data
250
+ # data = [
251
+ # {"latitudes": 1, "longitudes": 4, "color_scale": 10},
252
+ # {"latitudes": 2, "longitudes": 5, "color_scale": 20},
253
+ # {"latitudes": 3, "longitudes": 6, "color_scale": 30},
254
+ # ]
255
+
256
+ # # Call the map_table method and check if percentiles and outliers are calculated correctly
257
+ # markers = ds.Marker.map_table(data, include_color_scale_outliers=False)
258
+ # assert markers[0].colorbar_scale, [10, 20, 30]
259
+ # assert markers[0].outlier_min_bound, 10
260
+ # assert markers[0].outlier_max_bound, 30
261
+
262
+ # def test_return_colors():
263
+ # # Create a list of dictionaries to represent the table data
264
+ # data = [
265
+ # {"latitudes": 1, "longitudes": 4, "color_scale": 10},
266
+ # {"latitudes": 2, "longitudes": 5, "color_scale": 20},
267
+ # {"latitudes": 3, "longitudes": 6, "color_scale": 30},
268
+ # ]
269
+
270
+ # # Call the map_table method
271
+ # markers = ds.Marker.map_table(data, include_color_scale_outliers=False)
272
+
273
+ # # Call the interpolate_color method with a value that should use the last color
274
+ # last_color = markers[0].interpolate_color(["#340597", "#7008a5", "#a32494"], [10, 20], 25)
275
+ # assert last_color, "#a32494"
269
276
270
277
##########
271
278
# Region #
@@ -332,10 +339,7 @@ def test_color_values_and_ids(states):
332
339
333
340
def test_color_with_ids (states ):
334
341
# Case number of values and ids are different
335
- values = [1 , 2 , 3 , 4 , 5 ]
336
- ids = ['id1' , 'id2' , 'id3' ]
337
- colored = states .color (values , ids )
338
- assert ids == list (range (len (values )))
342
+ states .color ([1 , 2 , 3 , 4 , 5 ], []).show ()
339
343
340
344
###########
341
345
# GeoJSON #
@@ -425,7 +429,7 @@ def test_line_color_handling():
425
429
# Create a Circle instance with line_color attribute
426
430
circle = ds .Circle (37.8 , - 122 , line_color = 'red' )
427
431
# Call the _folium_kwargs method to get the attributes
428
- attrs = circle ._folium_kwargs ()
432
+ attrs = circle ._folium_kwargs
429
433
# Check that 'line_color' attribute has been transferred to 'color'
430
434
assert attrs ['color' ], 'red'
431
435
@@ -581,12 +585,3 @@ def test_remove_nonexistent_zip_code_column():
581
585
result = maps .get_coordinates (table , replace_columns = True )
582
586
# Ensure that the "zip code" column is removed
583
587
assert 'zip code' not in result .labels
584
-
585
- def test_remove_nonexistent_state_column ():
586
- # Create a table without the "state" column
587
- data = {'county' : ['County1' , 'County2' ], 'city' : ['City1' , 'City2' ]}
588
- table = ds .Table ().with_columns (data )
589
- # Call get_coordinates with remove_columns=True
590
- result = maps .get_coordinates (table , replace_columns = True )
591
- # Ensure that the "state" column is removed
592
- assert 'state' not in result .labels
0 commit comments