Skip to content

Commit 3c70918

Browse files
authored
Merge pull request #1099 from Conengmo/icon-color-warnings
Icon: warn for wrong color value
2 parents b4305bd + a536082 commit 3c70918

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

folium/map.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import json
1111
from collections import OrderedDict
1212

13+
import warnings
14+
1315
from branca.element import CssLink, Element, Figure, Html, JavascriptLink, MacroElement # noqa
1416

1517
from folium.utilities import _validate_coordinates, camelize, get_bounds
@@ -193,11 +195,19 @@ class Icon(MacroElement):
193195
{{this._parent.get_name()}}.setIcon({{this.get_name()}});
194196
{% endmacro %}
195197
""")
198+
color_options = {'red', 'darkred', 'lightred', 'orange', 'beige',
199+
'green', 'darkgreen', 'lightgreen',
200+
'blue', 'darkblue', 'cadetblue', 'lightblue',
201+
'purple', 'darkpurple', 'pink',
202+
'white', 'gray', 'lightgray' 'black'}
196203

197204
def __init__(self, color='blue', icon_color='white', icon='info-sign',
198205
angle=0, prefix='glyphicon'):
199206
super(Icon, self).__init__()
200207
self._name = 'Icon'
208+
if color not in self.color_options:
209+
warnings.warn('color argument of Icon should be one of: {}.'
210+
.format(self.color_options), stacklevel=2)
201211
self.color = color
202212
self.icon = icon
203213
self.icon_color = icon_color

tests/test_map.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
from __future__ import (absolute_import, division, print_function)
1010

11+
import pytest
12+
1113
from folium import Map
12-
from folium.map import Popup
14+
from folium.map import Popup, Icon
1315

1416

1517
tmpl = u"""
@@ -87,3 +89,17 @@ def test_popup_show():
8789
html_name=list(popup.html._children.keys())[0],
8890
map_name=m.get_name())
8991
assert _normalize(rendered) == _normalize(expected)
92+
93+
94+
def test_icon_valid_marker_colors():
95+
with pytest.warns(None) as record:
96+
for color in Icon.color_options:
97+
Icon(color=color)
98+
assert len(record) == 0
99+
100+
101+
@pytest.mark.filterwarnings('ignore::UserWarning')
102+
def test_icon_invalid_marker_colors():
103+
pytest.warns(UserWarning, Icon, color='lila')
104+
pytest.warns(UserWarning, Icon, color=42)
105+
pytest.warns(UserWarning, Icon, color=None)

0 commit comments

Comments
 (0)