/
test_map.py
89 lines (71 loc) · 2.63 KB
/
test_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
"""
Folium map Tests
----------------
"""
from __future__ import (absolute_import, division, print_function)
from folium import Map
from folium.map import Popup
tmpl = u"""
<div id="{id}"
style="width: {width}; height: {height};">
{text}</div>
""".format
def _normalize(rendered):
return ''.join(rendered.split())
def test_popup_ascii():
popup = Popup('Some text.')
_id = list(popup.html._children.keys())[0]
kw = {
'id': _id,
'width': '100.0%',
'height': '100.0%',
'text': 'Some text.',
}
assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
def test_popup_quotes():
popup = Popup("Let's try quotes", parse_html=True)
_id = list(popup.html._children.keys())[0]
kw = {
'id': _id,
'width': '100.0%',
'height': '100.0%',
'text': 'Let's try quotes',
}
assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
def test_popup_unicode():
popup = Popup(u"Ça c'est chouette", parse_html=True)
_id = list(popup.html._children.keys())[0]
kw = {
'id': _id,
'width': '100.0%',
'height': '100.0%',
'text': u'Ça c'est chouette',
}
assert ''.join(popup.html.render().split()) == ''.join(tmpl(**kw).split())
def test_popup_sticky():
m = Map()
popup = Popup('Some text.', sticky=True).add_to(m)
rendered = popup._template.render(this=popup, kwargs={})
expected = """
var {popup_name} = L.popup({{maxWidth: \'100%\', autoClose: false, closeOnClick: false}});
var {html_name} = $(`<div id="{html_name}" style="width: 100.0%; height: 100.0%;">Some text.</div>`)[0];
{popup_name}.setContent({html_name});
{map_name}.bindPopup({popup_name});
""".format(popup_name=popup.get_name(),
html_name=list(popup.html._children.keys())[0],
map_name=m.get_name())
assert _normalize(rendered) == _normalize(expected)
def test_popup_show():
m = Map()
popup = Popup('Some text.', show=True).add_to(m)
rendered = popup._template.render(this=popup, kwargs={})
expected = """
var {popup_name} = L.popup({{maxWidth: \'100%\' , autoClose: false}});
var {html_name} = $(`<div id="{html_name}" style="width: 100.0%; height: 100.0%;">Some text.</div>`)[0];
{popup_name}.setContent({html_name});
{map_name}.bindPopup({popup_name}).openPopup();
""".format(popup_name=popup.get_name(),
html_name=list(popup.html._children.keys())[0],
map_name=m.get_name())
assert _normalize(rendered) == _normalize(expected)