1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00
WeasyPrint/tests/test_unicode.py

36 lines
1.2 KiB
Python
Raw Normal View History

2022-03-25 13:47:27 +03:00
"""Test various unicode texts and filenames."""
2018-03-20 01:35:56 +03:00
2020-12-06 22:19:59 +03:00
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
2018-03-20 01:35:56 +03:00
@assert_no_logs
def test_unicode(assert_pixels_equal, tmp_path):
2018-03-20 01:35:56 +03:00
text = 'I løvë Unicode'
style = '''
2022-04-17 10:32:15 +03:00
@page { size: 200px 50px }
2018-03-20 01:35:56 +03:00
p { color: blue }
'''
2024-01-05 00:24:33 +03:00
expected_width, expected_height, expected_lines = html_to_pixels(f'''
<style>{style}</style>
<p><img src="pattern.png"> {text}</p>
''')
2018-03-20 01:35:56 +03:00
stylesheet = tmp_path / 'style.css'
image = tmp_path / 'pattern.png'
html = tmp_path / 'doc.html'
2024-01-04 13:44:51 +03:00
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>
'''
2024-01-04 13:59:35 +03:00
html.write_text(html_content, 'utf-8')
2018-03-20 01:35:56 +03:00
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)