File: test_unicode.py

package info (click to toggle)
weasyprint 67.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,896 kB
  • sloc: python: 61,025; makefile: 12
file content (35 lines) | stat: -rw-r--r-- 1,189 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
"""Test various unicode texts and filenames."""

from weasyprint.urls import ensure_url

from .draw import document_to_pixels, html_to_pixels
from .testing_utils import FakeHTML, assert_no_logs, resource_path


@assert_no_logs
def test_unicode(assert_pixels_equal, tmp_path):
    text = 'I løvë Unicode'
    style = '''
      @page { size: 200px 50px }
      p { color: blue }
    '''
    expected_width, expected_height, expected_lines = html_to_pixels(f'''
      <style>{style}</style>
      <p><img src="pattern.png"> {text}</p>
    ''')

    stylesheet = tmp_path / 'style.css'
    image = tmp_path / 'pattern.png'
    html = tmp_path / 'doc.html'
    stylesheet.write_text(style, 'utf-8')
    image.write_bytes(resource_path('pattern.png').read_bytes())
    html_content = f'''
      <link rel=stylesheet href="{ensure_url(str(stylesheet))}">
      <p><img src="{ensure_url(str(image))}"> {text}</p>
    '''
    html.write_text(html_content, 'utf-8')

    document = FakeHTML(html, encoding='utf-8')
    width, height, lines = document_to_pixels(document)
    assert (expected_width, expected_height) == (width, height)
    assert_pixels_equal(width, height, lines, expected_lines)