Skip to content

Commit 458f560

Browse files
VayelConengmo
andauthored
Keep map only in png screenshot (#1197)
* Keep map only in png screenshot * Add test for png size * Mark tests with selenium as bound to fail for Travis * Revert "Mark tests with selenium as bound to fail for Travis" This reverts commit f80da13. * remove deprecated find_elements_by_class_name * remove python 2 check Co-authored-by: Frank <[email protected]>
1 parent a0ee76e commit 458f560

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

folium/folium.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ def _to_png(self, delay=3, driver=None):
330330
driver.get('file:///{path}'.format(path=fname))
331331
driver.maximize_window()
332332
time.sleep(delay)
333-
png = driver.get_screenshot_as_png()
333+
div = driver.find_element('class name', 'folium-map')
334+
png = div.screenshot_as_png
334335
driver.quit()
335336
self._png_image = png
336337
return self._png_image

tests/test_repr.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import io
8-
import sys
98

109
import PIL.Image
1110

@@ -47,16 +46,22 @@ def test__repr_png_no_image(m):
4746
assert png is None
4847

4948

50-
@pytest.mark.xfail
5149
def test__repr_png_is_bytes(m_png):
5250
png = m_png._repr_png_()
5351
assert isinstance(png, bytes)
5452

5553

56-
@pytest.mark.xfail
57-
@pytest.mark.skipif(sys.version_info < (3, 0),
58-
reason="Doesn't work on Python 2.7.")
5954
def test_valid_png(m_png):
6055
png = m_png._repr_png_()
6156
img = PIL.Image.open(io.BytesIO(png))
62-
isinstance(img, PIL.PngImagePlugin.PngImageFile)
57+
assert isinstance(img, PIL.PngImagePlugin.PngImageFile)
58+
59+
60+
def test_valid_png_size(m_png):
61+
from folium.utilities import _parse_size
62+
w = h = 500
63+
m_png.width = _parse_size(w)
64+
m_png.height = _parse_size(h)
65+
png = m_png._repr_png_()
66+
img = PIL.Image.open(io.BytesIO(png))
67+
assert img.size == (w, h)

0 commit comments

Comments
 (0)