File: test_iframe.py

package info (click to toggle)
branca 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 332 kB
  • sloc: python: 1,484; javascript: 49; makefile: 15
file content (62 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (2)
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
"""
Folium Element Module class IFrame
----------------------
"""

import os

import pytest
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options

import branca.element as elem


def test_create_empty_iframe():
    iframe = elem.IFrame()
    iframe.render()


def test_create_iframe():
    iframe = elem.IFrame(html="<p>test content<p>", width=60, height=45)
    iframe.render()


@pytest.mark.headless
def test_rendering_utf8_iframe():
    iframe = elem.IFrame(html="<p>Cerrahpaşa Tıp Fakültesi</p>")

    options = Options()
    options.add_argument("-headless")
    driver = Firefox(options=options)

    driver.get("data:text/html," + iframe.render())
    driver.switch_to.frame(0)
    assert "Cerrahpaşa Tıp Fakültesi" in driver.page_source


@pytest.mark.headless
def test_rendering_figure_notebook():
    """Verify special characters are correctly rendered in Jupyter notebooks."""
    text = '5/7 %, Линейная улица, "\u00e9 Berdsk"'
    figure = elem.Figure()
    elem.Html(text).add_to(figure.html)
    html = figure._repr_html_()

    filepath = "temp_test_rendering_figure_notebook.html"
    filepath = os.path.abspath(filepath)
    with open(filepath, "w") as f:
        f.write(html)

    options = Options()
    options.add_argument("-headless")
    driver = Firefox(options=options)
    try:
        driver.get("file://" + filepath)
        driver.switch_to.frame(0)
        text_div = driver.find_element(By.CSS_SELECTOR, "div")
        assert text_div.text == text
    finally:
        os.remove(filepath)
        driver.quit()