# -*- coding: utf-8 -*-

""""
Folium _repr_*_ Tests
---------------------

"""

from __future__ import (absolute_import, division, print_function)

import sys
import io

import PIL.Image

import folium

import pytest


@pytest.fixture
def make_map(png_enabled=False):
    m = folium.Map(png_enabled=png_enabled)
    return m


def test__repr_html_is_str():
    html = make_map()._repr_html_()
    assert isinstance(html, str)


def test_valid_html():
    html = make_map()._repr_html_()
    parts = html.split('><')
    assert len(parts) == 6
    assert parts[0].lstrip('<div ') == 'style="width:100%;"'
    assert parts[1].lstrip('<div ') == 'style="position:relative;width:100%;height:0;padding-bottom:60%;"'  # noqa
    assert parts[2].startswith('iframe')
    assert parts[3] == '/iframe'
    assert parts[4] == '/div'
    assert parts[5] == '/div>'


def test__repr_png_no_image():
    png = make_map(png_enabled=False)._repr_png_()
    assert png is None


def test__repr_png_is_bytes():
    png = make_map(png_enabled=True)._repr_png_()
    assert isinstance(png, bytes)


@pytest.mark.skipif(sys.version_info < (3, 0),
                    reason="Doesn't work on Python 2.7.")
def test_valid_png():
    png = make_map(png_enabled=True)._repr_png_()
    img = PIL.Image.open(io.BytesIO(png))
    isinstance(img, PIL.PngImagePlugin.PngImageFile)

@@ -237,43 +237,92 @@
 ef m
-ake_map(png_enabled=False
+():%0A    yield folium.Map(png_enabled=False)%0A%0A%0A@pytest.fixture%0Adef m_png(
 ):%0A    
-m =
+yield
  fol
@@ -345,34 +345,13 @@
 led=
-png_enabled)%0A    return m%0A
+True)
 %0A%0Ade
@@ -375,16 +375,17 @@
 _is_str(
+m
 ):%0A    h
@@ -387,33 +387,24 @@
     html = m
-ake_map()
 ._repr_html_
@@ -461,16 +461,17 @@
 id_html(
+m
 ):%0A    h
@@ -481,17 +481,8 @@
  = m
-ake_map()
 ._re
@@ -889,16 +889,17 @@
 o_image(
+m
 ):%0A    p
@@ -908,34 +908,8 @@
  = m
-ake_map(png_enabled=False)
 ._re
@@ -971,16 +971,21 @@
 s_bytes(
+m_png
 ):%0A    p
@@ -994,33 +994,12 @@
  = m
-ake_map(png_enabled=True)
+_png
 ._re
@@ -1164,24 +1164,29 @@
 t_valid_png(
+m_png
 ):%0A    png =
@@ -1191,33 +1191,12 @@
  = m
-ake_map(png_enabled=True)
+_png
 ._re

fix tests for latest pytest