1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 08:27:22 +03:00
WeasyPrint/weasyprint/tests/test_layout/test_list.py
Guillaume Ayoub ec4504d23f Set a minimum height for empty list elements with outside marker
The spec says that we can do what we want to improve the rendering in such
cases. Adding a line would probably give exactly the same rendering as if there
were text, but the difference is so small that there's no need to hack the
formatting structure and keep the fix in 3 small lines during the layout.

Fix #873.
2019-05-31 16:56:52 +02:00

71 lines
1.8 KiB
Python

"""
weasyprint.tests.layout.list
----------------------------
Tests for lists layout.
:copyright: Copyright 2011-2019 Simon Sapin and contributors, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
@assert_no_logs
@pytest.mark.parametrize('inside', ('inside', '',))
@pytest.mark.parametrize('style, character', (
('circle', ''),
('disc', ''),
('square', ''),
))
def test_lists_style(inside, style, character):
page, = parse('''
<style>
body { margin: 0 }
ul { margin-left: 50px; list-style: %s %s }
</style>
<ul>
<li>abc</li>
</ul>
''' % (inside, style))
html, = page.children
body, = html.children
unordered_list, = body.children
list_item, = unordered_list.children
if inside:
line, = list_item.children
marker, content = line.children
else:
marker = list_item.outside_list_marker
assert marker.position_x == (
list_item.padding_box_x() - marker.width - marker.margin_right)
assert marker.position_y == list_item.position_y
line, = list_item.children
content, = line.children
assert marker.text == character
assert content.text == 'abc'
def test_lists_empty_item():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/873
page, = parse('''
<style>
body { margin: 0 }
ul { margin-left: 50px; list-style: %s %s }
</style>
<ul>
<li>a</li>
<li></li>
<li>a</li>
</ul>
''')
html, = page.children
body, = html.children
unordered_list, = body.children
li1, li2, li3 = unordered_list.children
assert li1.position_y != li2.position_y != li3.position_y