1
1
# -*- coding: utf-8 -*-
2
- '''
2
+ """
3
3
Folium Tests
4
4
-------
5
5
6
- '''
6
+ """
7
7
import json
8
8
import mock
9
9
import pandas as pd
16
16
17
17
18
18
def setup_data ():
19
- ''' Import economic data for testing'''
19
+ """ Import economic data for testing."""
20
20
with open ('us-counties.json' , 'r' ) as f :
21
21
get_id = json .load (f )
22
22
@@ -33,25 +33,25 @@ def setup_data():
33
33
34
34
35
35
def test_get_templates ():
36
- ''' Test template getting'''
36
+ """ Test template getting."""
37
37
38
38
env = folium .utilities .get_templates ()
39
39
nt .assert_is_instance (env , jinja2 .environment .Environment )
40
40
41
41
42
42
class testFolium (object ):
43
- ''' Test class for the Folium library'''
43
+ """ Test class for the Folium library."""
44
44
45
45
def setup (self ):
46
- ''' Setup Folium Map'''
46
+ """ Setup Folium Map."""
47
47
with mock .patch ('folium.folium.uuid4' ) as uuid4 :
48
48
uuid4 ().hex = '0' * 32
49
49
self .map = folium .Map (location = [45.5236 , - 122.6750 ], width = 900 ,
50
50
height = 400 , max_zoom = 20 , zoom_start = 4 )
51
51
self .env = Environment (loader = PackageLoader ('folium' , 'templates' ))
52
52
53
53
def test_init (self ):
54
- ''' Test map initialization'''
54
+ """ Test map initialization."""
55
55
56
56
assert self .map .map_type == 'base'
57
57
assert self .map .mark_cnt == {}
@@ -78,7 +78,7 @@ def test_init(self):
78
78
assert self .map .template_vars == tmpl
79
79
80
80
def test_cloudmade (self ):
81
- ''' Test cloudmade tiles and the API key'''
81
+ """ Test cloudmade tiles and the API key."""
82
82
83
83
nt .assert_raises (ValueError , callableObj = folium .Map ,
84
84
location = [45.5236 , - 122.6750 ], tiles = 'cloudmade' )
@@ -89,7 +89,7 @@ def test_cloudmade(self):
89
89
'/###/997/256/{z}/{x}/{y}.png' )
90
90
91
91
def test_builtin_tile (self ):
92
- ''' Test custom maptiles'''
92
+ """ Test custom maptiles."""
93
93
94
94
default_tiles = ['OpenStreetMap' , 'Stamen Terrain' , 'Stamen Toner' ]
95
95
for tiles in default_tiles :
@@ -102,7 +102,7 @@ def test_builtin_tile(self):
102
102
assert map .template_vars ['attr' ] == attr
103
103
104
104
def test_custom_tile (self ):
105
- ''' Test custom tile URLs'''
105
+ """ Test custom tile URLs."""
106
106
107
107
url = 'http://{s}.custom_tiles.org/{z}/{x}/{y}.png'
108
108
attr = 'Attribution for custom tiles'
@@ -115,7 +115,7 @@ def test_custom_tile(self):
115
115
assert map .template_vars ['attr' ] == attr
116
116
117
117
def test_wms_layer (self ):
118
- ''' Test wms layer URLs'''
118
+ """ Test WMS layer URLs."""
119
119
120
120
map = folium .Map (location = [44 , - 73 ], zoom_start = 3 )
121
121
wms_url = 'http://gis.srh.noaa.gov/arcgis/services/NDFDTemps/'
@@ -138,7 +138,7 @@ def test_wms_layer(self):
138
138
assert map .template_vars ['wms_layers' ][0 ] == wms
139
139
140
140
def test_simple_marker (self ):
141
- ''' Test simple marker addition'''
141
+ """ Test simple marker addition."""
142
142
143
143
mark_templ = self .env .get_template ('simple_marker.js' )
144
144
popup_templ = self .env .get_template ('simple_popup.js' )
@@ -148,9 +148,6 @@ def test_simple_marker(self):
148
148
mark_1 = mark_templ .render ({'marker' : 'marker_1' , 'lat' : 45.50 ,
149
149
'lon' : - 122.7 ,
150
150
'icon' : "{'icon':marker_1_icon}" })
151
- popup_1 = popup_templ .render ({'pop_name' : 'marker_1' ,
152
- 'pop_txt' : json .dumps ('Pop Text' ),
153
- 'width' : 300 })
154
151
assert self .map .template_vars ['custom_markers' ][0 ][1 ] == mark_1
155
152
assert self .map .template_vars ['custom_markers' ][0 ][2 ] == ""
156
153
@@ -172,7 +169,7 @@ def test_simple_marker(self):
172
169
assert self .map .template_vars ['custom_markers' ][2 ][2 ] == nopopup
173
170
174
171
def test_circle_marker (self ):
175
- ''' Test circle marker additions'''
172
+ """ Test circle marker additions."""
176
173
177
174
circ_templ = self .env .get_template ('circle_marker.js' )
178
175
@@ -195,7 +192,7 @@ def test_circle_marker(self):
195
192
assert self .map .template_vars ['markers' ][1 ][0 ] == circle_2
196
193
197
194
def test_poly_marker (self ):
198
- ''' Test polygon marker'''
195
+ """ Test polygon marker."""
199
196
200
197
poly_temp = self .env .get_template ('poly_marker.js' )
201
198
@@ -215,14 +212,14 @@ def test_poly_marker(self):
215
212
assert self .map .template_vars ['markers' ][0 ][0 ] == polygon
216
213
217
214
def test_latlng_pop (self ):
218
- ''' Test lat/lon popovers'''
215
+ """ Test lat/lon popovers."""
219
216
220
217
self .map .lat_lng_popover ()
221
218
pop_templ = self .env .get_template ('lat_lng_popover.js' ).render ()
222
219
assert self .map .template_vars ['lat_lng_pop' ] == pop_templ
223
220
224
221
def test_click_for_marker (self ):
225
- ''' Test click for marker functionality'''
222
+ """ Test click for marker functionality."""
226
223
227
224
# Lat/lon popover.
228
225
self .map .click_for_marker ()
@@ -238,7 +235,7 @@ def test_click_for_marker(self):
238
235
assert self .map .template_vars ['click_pop' ] == click
239
236
240
237
def test_vega_popup (self ):
241
- ''' Test vega popups'''
238
+ """ Test vega popups."""
242
239
243
240
vis = vincent .Bar (width = 675 - 75 , height = 350 - 50 , no_data = True )
244
241
@@ -253,7 +250,7 @@ def test_vega_popup(self):
253
250
assert self .map .template_vars ['custom_markers' ][0 ][2 ] == vega
254
251
255
252
def test_geo_json (self ):
256
- ''' Test geojson method'''
253
+ """ Test geojson method."""
257
254
258
255
path = 'us-counties.json'
259
256
geo_path = ".defer(d3.json, '{0}')" .format (path )
@@ -354,7 +351,7 @@ def test_geo_json(self):
354
351
assert templ ['topo_convert' ][0 ] == topo_func
355
352
356
353
def test_map_build (self ):
357
- ''' Test map build'''
354
+ """ Test map build."""
358
355
359
356
# Standard map.
360
357
self .map ._build_map ()
@@ -377,11 +374,11 @@ def test_map_build(self):
377
374
assert self .map .HTML == HTML
378
375
379
376
def test_tile_attr_unicode (self ):
380
- ''' Test tile attribution unicode
377
+ """ Test tile attribution unicode
381
378
382
379
Test not cover b'юникод'
383
380
because for python 3 bytes can only contain ASCII literal characters.
384
- '''
381
+ """
385
382
386
383
if not PY3 :
387
384
map = folium .Map (location = [45.5236 , - 122.6750 ],
@@ -396,27 +393,27 @@ def test_tile_attr_unicode(self):
396
393
map ._build_map ()
397
394
398
395
def test_create_map (self ):
399
- ''' Test create map'''
396
+ """ Test create map."""
400
397
401
398
map = folium .Map (location = [45.5236 , - 122.6750 ],
402
399
tiles = 'test' , attr = 'юникод' )
403
400
404
- # Add json data
401
+ # Add json data.
405
402
path = 'us-counties.json'
406
403
data = setup_data ()
407
404
map .geo_json (geo_path = path , data = data ,
408
405
columns = ['FIPS_Code' , 'Unemployed_2011' ],
409
406
key_on = 'feature.id' , fill_color = 'YlGnBu' ,
410
407
reset = True )
411
408
412
- # Add plugins
409
+ # Add plugins.
413
410
map .polygon_marker (location = [45.5 , - 122.5 ])
414
411
415
- # Test write
412
+ # Test write.
416
413
map .create_map ()
417
414
418
415
def test_line (self ):
419
- ''' Test line'''
416
+ """ Test line."""
420
417
421
418
line_temp = self .env .get_template ('polyline.js' )
422
419
@@ -431,27 +428,26 @@ def test_line(self):
431
428
[[45.5238 , - 122.6750 ], [45.5238 , - 122.6751 ]]
432
429
]
433
430
line_rendered = line_temp .render ({'line' : 'line_1' ,
434
- 'locations' : locations , 'options' : line_opts })
431
+ 'locations' : locations ,
432
+ 'options' : line_opts })
435
433
436
434
self .map .line (locations = locations ,
437
- line_color = line_opts ['color' ],
438
- line_weight = line_opts ['weight' ],
439
- line_opacity = line_opts ['opacity' ])
435
+ line_color = line_opts ['color' ],
436
+ line_weight = line_opts ['weight' ],
437
+ line_opacity = line_opts ['opacity' ])
440
438
assert self .map .template_vars ['lines' ][0 ][0 ] == line_rendered
441
439
442
440
def test_multi_polyline (self ):
443
- ''' Test multi_polyline'''
441
+ """ Test multi_polyline."""
444
442
445
443
multiline_temp = self .env .get_template ('multi_polyline.js' )
446
444
447
445
multiline_opts = {'color' : 'blue' ,
448
- 'weight' : 2 ,
449
- 'opacity' : 1 }
450
- locations = [
451
- [[45.5236 , - 122.6750 ], [45.5236 , - 122.6751 ]],
452
- [[45.5237 , - 122.6750 ], [45.5237 , - 122.6751 ]],
453
- [[45.5238 , - 122.6750 ], [45.5238 , - 122.6751 ]]
454
- ]
446
+ 'weight' : 2 ,
447
+ 'opacity' : 1 }
448
+ locations = [[[45.5236 , - 122.6750 ], [45.5236 , - 122.6751 ]],
449
+ [[45.5237 , - 122.6750 ], [45.5237 , - 122.6751 ]],
450
+ [[45.5238 , - 122.6750 ], [45.5238 , - 122.6751 ]]]
455
451
multiline_rendered = multiline_temp .render ({'multiline' : 'multiline_1' ,
456
452
'locations' : locations ,
457
453
'options' : multiline_opts })
@@ -463,23 +459,22 @@ def test_multi_polyline(self):
463
459
assert self .map .template_vars ['multilines' ][0 ][0 ] == multiline_rendered
464
460
465
461
def test_fit_bounds (self ):
466
- """Test fit_bounds"""
462
+ """Test fit_bounds. """
467
463
bounds = ((52.193636 , - 2.221575 ), (52.636878 , - 1.139759 ))
468
464
fit_bounds_tpl = self .env .get_template ('fit_bounds.js' )
469
465
fit_bounds_rendered = fit_bounds_tpl .render ({
470
- 'bounds' : json .dumps (bounds ),
471
- 'fit_bounds_options' : {},
472
- })
466
+ 'bounds' : json .dumps (bounds ),
467
+ 'fit_bounds_options' : {}, })
473
468
474
469
self .map .fit_bounds (bounds )
475
470
assert self .map .template_vars ['fit_bounds' ] == fit_bounds_rendered
476
471
477
472
fit_bounds_tpl = self .env .get_template ('fit_bounds.js' )
478
473
fit_bounds_rendered = fit_bounds_tpl .render ({
479
- 'bounds' : json .dumps (bounds ),
480
- 'fit_bounds_options' : json .dumps ({'padding' : (3 ,3 ), 'maxZoom' : 15 }),
481
- })
474
+ 'bounds' : json .dumps (bounds ),
475
+ 'fit_bounds_options' : json .dumps ({'maxZoom' : 15 ,
476
+ 'padding' : (3 , 3 ), }),
477
+ }, sort_keys = True )
482
478
483
479
self .map .fit_bounds (bounds , max_zoom = 15 , padding = (3 , 3 ))
484
480
assert self .map .template_vars ['fit_bounds' ] == fit_bounds_rendered
485
-
0 commit comments