Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/test_repr.py
1593 views
1
""" "
2
Folium _repr_*_ Tests
3
---------------------
4
5
"""
6
7
import io
8
9
import PIL.Image
10
import pytest
11
12
import folium
13
14
15
@pytest.fixture
16
def m():
17
yield folium.Map(png_enabled=False)
18
19
20
@pytest.fixture
21
def m_png():
22
yield folium.Map(png_enabled=True)
23
24
25
def test__repr_html_is_str(m):
26
html = m._repr_html_()
27
assert isinstance(html, str)
28
29
30
def test_valid_html(m):
31
html = m._repr_html_()
32
parts = html.split("><")
33
assert len(parts) == 7
34
assert parts[0].lstrip("<div ") == 'style="width:100%;"'
35
assert (
36
parts[1].lstrip("<div ")
37
== 'style="position:relative;width:100%;height:0;padding-bottom:60%;"'
38
) # noqa
39
assert "make this notebook trusted" in parts[2].lower()
40
assert parts[3].startswith("iframe")
41
assert parts[4] == "/iframe"
42
assert parts[5] == "/div"
43
assert parts[6] == "/div>"
44
45
46
def test__repr_png_no_image(m):
47
png = m._repr_png_()
48
assert png is None
49
50
51
def test__repr_png_is_bytes(m_png):
52
png = m_png._repr_png_()
53
assert isinstance(png, bytes)
54
55
56
def test_valid_png(m_png):
57
png = m_png._repr_png_()
58
img = PIL.Image.open(io.BytesIO(png))
59
assert isinstance(img, PIL.PngImagePlugin.PngImageFile)
60
61
62
def test_valid_png_size(m_png):
63
from folium.utilities import _parse_size
64
65
w = h = 500
66
m_png.width = _parse_size(w)
67
m_png.height = _parse_size(h)
68
png = m_png._repr_png_()
69
img = PIL.Image.open(io.BytesIO(png))
70
assert img.size == (w, h)
71
72