11"""Tests for the foliumap module."""
22
3- from __future__ import annotations
4-
53import json
64import os
75import tempfile
108
119try :
1210 import sys
13- import importlib
1411 import folium
1512
1613 _fake_basemaps = {
@@ -75,38 +72,34 @@ class FoliumapTest(unittest.TestCase):
7572 def _make_map (self , ** kwargs ) -> foliumap .Map :
7673 return foliumap .Map (ee_initialize = False , ** kwargs )
7774
78- # ------------------------------------------------------------------ #
79- # Map initialization
80- # ------------------------------------------------------------------ #
81-
82- def test_map_init_default_params (self ) -> None :
75+ def test_map_init_default_params (self ):
8376 m = self ._make_map ()
8477 self .assertIsInstance (m , folium .Map )
8578 self .assertEqual (m .location , [20 , 0 ])
8679 self .assertEqual (m .options ["zoom" ], 2 )
8780
88- def test_map_init_custom_center (self ) -> None :
81+ def test_map_init_custom_center (self ):
8982 m = self ._make_map (center = [40 , - 100 ])
9083 self .assertEqual (m .location , [40 , - 100 ])
9184
92- def test_map_init_custom_zoom (self ) -> None :
85+ def test_map_init_custom_zoom (self ):
9386 m = self ._make_map (zoom = 10 )
9487 self .assertEqual (m .options ["zoom" ], 10 )
9588
96- def test_map_init_location_param (self ) -> None :
89+ def test_map_init_location_param (self ):
9790 m = self ._make_map (location = [35 , 139 ])
9891 self .assertEqual (m .location , [35 , 139 ])
9992
100- def test_map_baseclass (self ) -> None :
93+ def test_map_baseclass (self ):
10194 m = self ._make_map ()
10295 self .assertEqual (m .baseclass , "folium" )
10396
104- def test_map_init_draw_features_empty (self ) -> None :
97+ def test_map_init_draw_features_empty (self ):
10598 m = self ._make_map ()
10699 self .assertEqual (m .draw_features , [])
107100 self .assertIsNone (m .draw_last_feature )
108101
109- def test_map_max_zoom_default (self ) -> None :
102+ def test_map_max_zoom_default (self ):
110103 m = self ._make_map ()
111104 # The default fit_bounds call uses maxZoom; verify via the FitBounds child.
112105 fit_children = [
@@ -115,11 +108,7 @@ def test_map_max_zoom_default(self) -> None:
115108 self .assertTrue (len (fit_children ) > 0 )
116109 self .assertEqual (fit_children [0 ].options .get ("maxZoom" ), 2 )
117110
118- # ------------------------------------------------------------------ #
119- # set_center
120- # ------------------------------------------------------------------ #
121-
122- def test_set_center_updates_bounds (self ) -> None :
111+ def test_set_center_updates_bounds (self ):
123112 m = self ._make_map ()
124113 m .set_center (- 122.4 , 37.8 , zoom = 12 )
125114 # folium stores bounds via FitBounds children, not in get_bounds().
@@ -130,11 +119,7 @@ def test_set_center_updates_bounds(self) -> None:
130119 self .assertAlmostEqual (last .bounds [0 ][0 ], 37.8 , places = 1 )
131120 self .assertAlmostEqual (last .bounds [0 ][1 ], - 122.4 , places = 1 )
132121
133- # ------------------------------------------------------------------ #
134- # zoom_to_bounds
135- # ------------------------------------------------------------------ #
136-
137- def test_zoom_to_bounds_updates_bounds (self ) -> None :
122+ def test_zoom_to_bounds_updates_bounds (self ):
138123 m = self ._make_map ()
139124 m .zoom_to_bounds ([- 122.5 , 37.5 , - 122.0 , 38.0 ])
140125 # folium stores bounds via FitBounds children.
@@ -149,11 +134,7 @@ def test_zoom_to_bounds_updates_bounds(self) -> None:
149134 self .assertAlmostEqual (north , 38.0 , places = 1 )
150135 self .assertAlmostEqual (east , - 122.0 , places = 1 )
151136
152- # ------------------------------------------------------------------ #
153- # add_tile_layer
154- # ------------------------------------------------------------------ #
155-
156- def test_add_tile_layer_increases_children (self ) -> None :
137+ def test_add_tile_layer_increases_children (self ):
157138 m = self ._make_map ()
158139 children_before = len (m ._children )
159140 m .add_tile_layer (
@@ -163,7 +144,7 @@ def test_add_tile_layer_increases_children(self) -> None:
163144 )
164145 self .assertGreater (len (m ._children ), children_before )
165146
166- def test_add_tile_layer_name_in_children (self ) -> None :
147+ def test_add_tile_layer_name_in_children (self ):
167148 m = self ._make_map ()
168149 m .add_tile_layer (
169150 tiles = "https://tile.example.com/{z}/{x}/{y}.png" ,
@@ -177,11 +158,7 @@ def test_add_tile_layer_name_in_children(self) -> None:
177158 # The tile layer name should appear in children tile_name attributes.
178159 self .assertIn ("MyTiles" , child_names )
179160
180- # ------------------------------------------------------------------ #
181- # add_wms_layer
182- # ------------------------------------------------------------------ #
183-
184- def test_add_wms_layer_increases_children (self ) -> None :
161+ def test_add_wms_layer_increases_children (self ):
185162 m = self ._make_map ()
186163 children_before = len (m ._children )
187164 m .add_wms_layer (
@@ -191,32 +168,24 @@ def test_add_wms_layer_increases_children(self) -> None:
191168 )
192169 self .assertGreater (len (m ._children ), children_before )
193170
194- # ------------------------------------------------------------------ #
195- # add_marker
196- # ------------------------------------------------------------------ #
197-
198- def test_add_marker_list (self ) -> None :
171+ def test_add_marker_list (self ):
199172 m = self ._make_map ()
200173 children_before = len (m ._children )
201174 m .add_marker (location = [37.8 , - 122.4 ], popup = "Test" )
202175 self .assertGreater (len (m ._children ), children_before )
203176
204- def test_add_marker_tuple (self ) -> None :
177+ def test_add_marker_tuple (self ):
205178 m = self ._make_map ()
206179 children_before = len (m ._children )
207180 m .add_marker (location = (37.8 , - 122.4 ), tooltip = "Tooltip" )
208181 self .assertGreater (len (m ._children ), children_before )
209182
210- def test_add_marker_invalid_type_raises (self ) -> None :
183+ def test_add_marker_invalid_type_raises (self ):
211184 m = self ._make_map ()
212185 with self .assertRaises (TypeError ):
213186 m .add_marker (location = "invalid" )
214187
215- # ------------------------------------------------------------------ #
216- # add_geojson
217- # ------------------------------------------------------------------ #
218-
219- def test_add_geojson_from_dict (self ) -> None :
188+ def test_add_geojson_from_dict (self ):
220189 m = self ._make_map ()
221190 geojson_data = {
222191 "type" : "FeatureCollection" ,
@@ -235,7 +204,7 @@ def test_add_geojson_from_dict(self) -> None:
235204 m .add_geojson (geojson_data , layer_name = "GeoJSON Test" )
236205 self .assertGreater (len (m ._children ), children_before )
237206
238- def test_add_geojson_from_file (self ) -> None :
207+ def test_add_geojson_from_file (self ):
239208 geojson_data = {
240209 "type" : "FeatureCollection" ,
241210 "features" : [
@@ -258,44 +227,36 @@ def test_add_geojson_from_file(self) -> None:
258227 m .add_geojson (filepath , layer_name = "File GeoJSON" )
259228 self .assertGreater (len (m ._children ), children_before )
260229
261- def test_add_geojson_file_not_found_raises (self ) -> None :
230+ def test_add_geojson_file_not_found_raises (self ):
262231 m = self ._make_map ()
263232 with self .assertRaises (Exception ):
264233 m .add_geojson ("/nonexistent/path.geojson" )
265234
266- def test_add_geojson_invalid_type_raises (self ) -> None :
235+ def test_add_geojson_invalid_type_raises (self ):
267236 m = self ._make_map ()
268237 with self .assertRaises (Exception ):
269238 m .add_geojson (12345 )
270239
271- # ------------------------------------------------------------------ #
272- # add_heatmap
273- # ------------------------------------------------------------------ #
274-
275- def test_add_heatmap_from_list (self ) -> None :
240+ def test_add_heatmap_from_list (self ):
276241 m = self ._make_map ()
277242 data = [[37.8 , - 122.4 , 1.0 ], [37.9 , - 122.3 , 2.0 ]]
278243 children_before = len (m ._children )
279244 m .add_heatmap (data = data , name = "Heat" )
280245 self .assertGreater (len (m ._children ), children_before )
281246
282- def test_add_heatmap_invalid_data_raises (self ) -> None :
247+ def test_add_heatmap_invalid_data_raises (self ):
283248 m = self ._make_map ()
284249 with self .assertRaises (ValueError ):
285250 m .add_heatmap (data = 12345 )
286251
287- # ------------------------------------------------------------------ #
288- # to_html
289- # ------------------------------------------------------------------ #
290-
291- def test_to_html_returns_string (self ) -> None :
252+ def test_to_html_returns_string (self ):
292253 m = self ._make_map ()
293254 html = m .to_html ()
294255 self .assertIsInstance (html , str )
295256 self .assertIn ("<html>" , html .lower ())
296257 self .assertIn ("leaflet" , html .lower ())
297258
298- def test_to_html_saves_file (self ) -> None :
259+ def test_to_html_saves_file (self ):
299260 with tempfile .TemporaryDirectory () as tmpdir :
300261 filepath = os .path .join (tmpdir , "test_map.html" )
301262 m = self ._make_map ()
@@ -306,26 +267,18 @@ def test_to_html_saves_file(self) -> None:
306267 self .assertIn ("<html>" , content .lower ())
307268 self .assertIn ("leaflet" , content .lower ())
308269
309- def test_to_html_invalid_extension_raises (self ) -> None :
270+ def test_to_html_invalid_extension_raises (self ):
310271 m = self ._make_map ()
311272 with self .assertRaises (ValueError ):
312273 m .to_html ("output.txt" )
313274
314- # ------------------------------------------------------------------ #
315- # add_layer_control
316- # ------------------------------------------------------------------ #
317-
318- def test_add_layer_control (self ) -> None :
275+ def test_add_layer_control (self ):
319276 m = self ._make_map ()
320277 children_before = len (m ._children )
321278 m .add_layer_control ()
322279 self .assertGreater (len (m ._children ), children_before )
323280
324- # ------------------------------------------------------------------ #
325- # set_control_visibility
326- # ------------------------------------------------------------------ #
327-
328- def test_set_control_visibility_adds_children (self ) -> None :
281+ def test_set_control_visibility_adds_children (self ):
329282 m = self ._make_map ()
330283 children_before = len (m ._children )
331284 m .set_control_visibility (
@@ -335,26 +288,18 @@ def test_set_control_visibility_adds_children(self) -> None:
335288 )
336289 self .assertGreater (len (m ._children ), children_before )
337290
338- # ------------------------------------------------------------------ #
339- # setOptions
340- # ------------------------------------------------------------------ #
341-
342- def test_set_options_adds_basemap (self ) -> None :
291+ def test_set_options_adds_basemap (self ):
343292 m = self ._make_map ()
344293 children_before = len (m ._children )
345294 m .setOptions ("HYBRID" )
346295 self .assertGreater (len (m ._children ), children_before )
347296
348- def test_set_options_invalid_basemap_raises (self ) -> None :
297+ def test_set_options_invalid_basemap_raises (self ):
349298 m = self ._make_map ()
350299 with self .assertRaises (Exception ):
351300 m .setOptions ("INVALID_BASEMAP_XYZ" )
352301
353- # ------------------------------------------------------------------ #
354- # add_cog_mosaic (deprecated)
355- # ------------------------------------------------------------------ #
356-
357- def test_add_cog_mosaic_raises_not_implemented (self ) -> None :
302+ def test_add_cog_mosaic_raises_not_implemented (self ):
358303 m = self ._make_map ()
359304 with self .assertRaises (NotImplementedError ):
360305 m .add_cog_mosaic ()
0 commit comments