1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-03 23:48:07 +03:00

Rename folders and imports in tests

This commit is contained in:
Guillaume Ayoub 2021-04-19 17:15:53 +02:00
parent 6bf74c7de2
commit 111191f7bc
50 changed files with 249 additions and 265 deletions

2
.gitignore vendored
View File

@ -5,5 +5,5 @@
/dist
/docs/_build
/pytest_cache
/tests/test_draw/results
/tests/draw/results
/venv

View File

@ -9,13 +9,12 @@
import pytest
from weasyprint.formatting_structure import boxes
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
def test_block_widths():
page, = parse('''
page, = render_pages('''
<style>
@page { margin: 0; size: 120px 2000px }
body { margin: 0 }
@ -138,7 +137,7 @@ def test_block_widths():
@assert_no_logs
def test_block_heights_p():
page, = parse('''
page, = render_pages('''
<style>
@page { margin: 0; size: 100px 20000px }
html, body { margin: 0 }
@ -168,7 +167,7 @@ def test_block_heights_p():
@assert_no_logs
def test_block_heights_img():
page, = parse('''
page, = render_pages('''
<style>
body { height: 200px; font-size: 0 }
</style>
@ -196,7 +195,7 @@ def test_block_heights_img():
@assert_no_logs
def test_block_heights_img_no_body_height():
# Same but with no height on body: percentage *-height is ignored
page, = parse('''
page, = render_pages('''
<style>
body { font-size: 0 }
</style>
@ -223,7 +222,7 @@ def test_block_heights_img_no_body_height():
@assert_no_logs
def test_block_percentage_heights_no_html_height():
page, = parse('''
page, = render_pages('''
<style>
html, body { margin: 0 }
body { height: 50% }
@ -240,7 +239,7 @@ def test_block_percentage_heights_no_html_height():
@assert_no_logs
def test_block_percentage_heights():
page, = parse('''
page, = render_pages('''
<style>
html, body { margin: 0 }
html { height: 300px }
@ -265,7 +264,7 @@ def test_block_percentage_heights():
))
def test_box_sizing(size):
# http://www.w3.org/TR/css3-ui/#box-sizing
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100000px }
body { width: 10000px; margin: 0 }
@ -320,7 +319,7 @@ def test_box_sizing(size):
))
def test_box_sizing_zero(size):
# http://www.w3.org/TR/css3-ui/#box-sizing
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100000px }
body { width: 10000px; margin: 0 }
@ -366,7 +365,7 @@ NOT_COLLAPSING = (
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_1(margin_1, margin_2, result):
# Siblings
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#p1 { margin-bottom: %s }
@ -386,7 +385,7 @@ def test_vertical_space_1(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_2(margin_1, margin_2, result):
# Not siblings, first is nested
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#p1 { margin-bottom: %s }
@ -409,7 +408,7 @@ def test_vertical_space_2(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_3(margin_1, margin_2, result):
# Not siblings, second is nested
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#p1 { margin-bottom: %s }
@ -432,7 +431,7 @@ def test_vertical_space_3(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_4(margin_1, margin_2, result):
# Not siblings, second is doubly nested
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#p1 { margin-bottom: %s }
@ -458,7 +457,7 @@ def test_vertical_space_4(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_5(margin_1, margin_2, result):
# Collapsing with children
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#div1 { margin-top: %s }
@ -487,7 +486,7 @@ def test_vertical_space_5(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', NOT_COLLAPSING)
def test_vertical_space_6(margin_1, margin_2, result):
# Block formatting context: Not collapsing with children
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#div1 { margin-top: %s; overflow: hidden }
@ -513,7 +512,7 @@ def test_vertical_space_6(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_7(margin_1, margin_2, result):
# Collapsing through an empty div
page, = parse('''
page, = render_pages('''
<style>
p { font: 20px/1 serif } /* block height == 20px */
#p1 { margin-bottom: %s }
@ -535,7 +534,7 @@ def test_vertical_space_7(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', NOT_COLLAPSING)
def test_vertical_space_8(margin_1, margin_2, result):
# The root element does not collapse
page, = parse('''
page, = render_pages('''
<style>
html { margin-top: %s }
body { margin-top: %s }
@ -553,7 +552,7 @@ def test_vertical_space_8(margin_1, margin_2, result):
@pytest.mark.parametrize('margin_1, margin_2, result', COLLAPSING)
def test_vertical_space_9(margin_1, margin_2, result):
# <body> DOES collapse
page, = parse('''
page, = render_pages('''
<style>
body { margin-top: %s }
div { margin-top: %s }
@ -573,7 +572,7 @@ def test_vertical_space_9(margin_1, margin_2, result):
@assert_no_logs
def test_box_decoration_break_block_slice():
# http://www.w3.org/TR/css3-background/#the-box-decoration-break
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 100px }
p { padding: 2px; border: 3px solid; margin: 5px }
@ -622,7 +621,7 @@ def test_box_decoration_break_block_slice():
@assert_no_logs
def test_box_decoration_break_block_clone():
# http://www.w3.org/TR/css3-background/#the-box-decoration-break
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 100px }
p { padding: 2px; border: 3px solid; margin: 5px;
@ -675,7 +674,7 @@ def test_box_decoration_break_block_clone():
@assert_no_logs
def test_box_decoration_break_clone_bottom_padding():
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 80px; margin: 0 }
div { height: 20px }
@ -711,7 +710,7 @@ def test_box_decoration_break_slice_bottom_padding(): # pragma: no cover
# with its bottom border/padding doesn't cross the bottom line. If it does,
# we should re-render the box with a max_position_y including the bottom
# border/padding.
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 80px; margin: 0 }
div { height: 20px }
@ -740,7 +739,7 @@ def test_box_decoration_break_slice_bottom_padding(): # pragma: no cover
@assert_no_logs
def test_overflow_auto():
page, = parse('''
page, = render_pages('''
<article style="overflow: auto">
<div style="float: left; height: 50px; margin: 10px">bla bla bla</div>
toto toto''')
@ -753,7 +752,7 @@ def test_overflow_auto():
@assert_no_logs
def test_box_margin_top_repagination():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/943
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 50px }
:root { line-height: 1; font-size: 10px }
@ -779,7 +778,7 @@ def test_box_margin_top_repagination():
@assert_no_logs
def test_continue_discard():
page_1, = parse('''
page_1, = render_pages('''
<style>
@page { size: 80px; margin: 0 }
div { display: inline-block; width: 100%; height: 25px }
@ -806,7 +805,7 @@ def test_continue_discard():
@assert_no_logs
def test_continue_discard_children():
page_1, = parse('''
page_1, = render_pages('''
<style>
@page { size: 80px; margin: 0 }
div { display: inline-block; width: 100%; height: 25px }

View File

@ -8,8 +8,7 @@
import pytest
from ..test_boxes import render_pages
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs

View File

@ -8,8 +8,7 @@
import pytest
from ..test_boxes import render_pages
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs

View File

@ -9,12 +9,11 @@
import pytest
from weasyprint.formatting_structure import boxes
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs, capture_logs
from ..testing_utils import assert_no_logs, capture_logs, render_pages
def get_img(html):
page, = parse(html)
page, = render_pages(html)
html, = page.children
body, = html.children
line, = body.children
@ -110,7 +109,7 @@ def test_images_4(url):
@assert_no_logs
def test_images_5():
with capture_logs() as logs:
parse('<img src=nonexistent.png><img src=nonexistent.png>')
render_pages('<img src=nonexistent.png><img src=nonexistent.png>')
# Failures are cached too: only one error
assert len(logs) == 1
assert 'ERROR: Failed to load image' in logs[0]
@ -168,7 +167,7 @@ def test_images_10():
@assert_no_logs
def test_images_11():
# display: table-cell is ignored. XXX Should it?
page, = parse('''<body style="font-size: 0">
page, = render_pages('''<body style="font-size: 0">
<img src="pattern.png" style="width: 40px">
<img src="pattern.png" style="width: 60px; display: table-cell">
''')
@ -188,7 +187,7 @@ def test_images_11():
@assert_no_logs
def test_images_12():
# Block-level image:
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100px }
img { width: 40px; margin: 10px auto; display: block }
@ -210,7 +209,7 @@ def test_images_12():
@assert_no_logs
def test_images_13():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100px }
img { min-width: 40%; margin: 10px auto; display: block }
@ -232,7 +231,7 @@ def test_images_13():
@assert_no_logs
def test_images_14():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100px }
img { min-width: 40px; margin: 10px auto; display: block }
@ -254,7 +253,7 @@ def test_images_14():
@assert_no_logs
def test_images_15():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 100px }
img { min-height: 30px; max-width: 2px;
@ -277,7 +276,7 @@ def test_images_15():
@assert_no_logs
def test_images_16():
page, = parse('''
page, = render_pages('''
<body style="float: left">
<img style="height: 200px; margin: 10px; display: block" src="
data:image/svg+xml,
@ -296,7 +295,7 @@ def test_images_16():
@assert_no_logs
def test_images_17():
page, = parse('''
page, = render_pages('''
<div style="width: 300px; height: 300px">
<img src="
data:image/svg+xml,
@ -317,7 +316,7 @@ def test_images_17():
@assert_no_logs
def test_images_18():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/1050
page, = parse('''
page, = render_pages('''
<img style="position: absolute" src="
data:image/svg+xml,
<svg viewBox='0 0 20 10'></svg>
@ -332,7 +331,7 @@ def test_linear_gradient():
def layout(gradient_css, type_='linear', init=(),
positions=[0, 1], colors=[blue, lime]):
page, = parse('<style>@page { background: ' + gradient_css)
page, = render_pages('<style>@page { background: ' + gradient_css)
layer, = page.background.layers
result = layer.image.layout(400, 300)
assert result[0] == 1
@ -397,7 +396,7 @@ def test_radial_gradient():
center_x, center_y, radius0, radius1 = init
init = (center_x, center_y / scale_y, radius0,
center_x, center_y / scale_y, radius1)
page, = parse('<style>@page { background: ' + gradient_css)
page, = render_pages('<style>@page { background: ' + gradient_css)
layer, = page.background.layers
result = layer.image.layout(400, 300)
assert result[0] == scale_y

View File

@ -9,13 +9,12 @@
import pytest
from weasyprint.formatting_structure import boxes
from ..test_boxes import render_pages as parse
from ..testing_utils import SANS_FONTS, assert_no_logs
from ..testing_utils import SANS_FONTS, assert_no_logs, render_pages
@assert_no_logs
def test_empty_linebox():
page, = parse('<p> </p>')
page, = render_pages('<p> </p>')
html, = page.children
body, = html.children
paragraph, = body.children
@ -27,13 +26,13 @@ def test_empty_linebox():
@assert_no_logs
def test_empty_linebox_removed_space():
# Whitespace removed at the beginning of the line => empty line => no line
page, = parse('''
page, = render_pages('''
<style>
p { width: 1px }
</style>
<p><br> </p>
''')
page, = parse('<p> </p>')
page, = render_pages('<p> </p>')
html, = page.children
body, = html.children
paragraph, = body.children
@ -43,7 +42,7 @@ def test_empty_linebox_removed_space():
@assert_no_logs
def test_breaking_linebox():
page, = parse('''
page, = render_pages('''
<style>
p { font-size: 13px;
width: 300px;
@ -77,7 +76,7 @@ def test_breaking_linebox():
@assert_no_logs
def test_position_x_ltr():
page, = parse('''
page, = render_pages('''
<style>
span {
padding: 0 10px 0 15px;
@ -105,7 +104,7 @@ def test_position_x_ltr():
@assert_no_logs
def test_position_x_rtl():
page, = parse('''
page, = render_pages('''
<style>
body {
direction: rtl;
@ -138,7 +137,7 @@ def test_position_x_rtl():
@assert_no_logs
def test_breaking_linebox_regression_1():
# See http://unicode.org/reports/tr14/
page, = parse('<pre>a\nb\rc\r\nd\u2029e</pre>')
page, = render_pages('<pre>a\nb\rc\r\nd\u2029e</pre>')
html, = page.children
body, = html.children
pre, = body.children
@ -160,7 +159,7 @@ def test_breaking_linebox_regression_2():
<span style="padding-right: 1em; margin-right: 1em">c def</span>g
hi</p>'''
for i in range(16):
page, = parse(html_sample % i)
page, = render_pages(html_sample % i)
html, = page.children
body, = html.children
p, = body.children
@ -234,7 +233,7 @@ def test_breaking_linebox_regression_2():
@assert_no_logs
def test_breaking_linebox_regression_3():
# Regression test #1 for https://github.com/Kozea/WeasyPrint/issues/560
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -255,7 +254,7 @@ def test_breaking_linebox_regression_3():
@assert_no_logs
def test_breaking_linebox_regression_4():
# Regression test #2 for https://github.com/Kozea/WeasyPrint/issues/560
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -275,7 +274,7 @@ def test_breaking_linebox_regression_4():
@assert_no_logs
def test_breaking_linebox_regression_5():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/580
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -295,7 +294,7 @@ def test_breaking_linebox_regression_5():
@assert_no_logs
def test_breaking_linebox_regression_6():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/586
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -312,7 +311,7 @@ def test_breaking_linebox_regression_6():
@assert_no_logs
def test_breaking_linebox_regression_7():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/660
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -331,7 +330,7 @@ def test_breaking_linebox_regression_7():
@assert_no_logs
def test_breaking_linebox_regression_8():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/783
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -351,11 +350,11 @@ def test_breaking_linebox_regression_8():
@pytest.mark.xfail
@assert_no_logs
def test_breaking_linebox_regression_9(): # pragma: no cover
def test_breaking_linebox_regression_9():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/783
# TODO: inlines.can_break_inside return False for span but we can break
# before the <b> tag. can_break_inside should be fixed.
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -375,7 +374,7 @@ def test_breaking_linebox_regression_9(): # pragma: no cover
@assert_no_logs
def test_breaking_linebox_regression_10():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/923
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -398,7 +397,7 @@ def test_breaking_linebox_regression_10():
@assert_no_logs
def test_breaking_linebox_regression_11():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -418,7 +417,7 @@ def test_breaking_linebox_regression_11():
@assert_no_logs
def test_breaking_linebox_regression_12():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -437,7 +436,7 @@ def test_breaking_linebox_regression_12():
@assert_no_logs
def test_breaking_linebox_regression_13():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/953
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -456,7 +455,7 @@ def test_breaking_linebox_regression_13():
@assert_no_logs
def test_linebox_text():
page, = parse('''
page, = render_pages('''
<style>
p { width: 165px; font-family:%(fonts)s;}
</style>
@ -484,7 +483,7 @@ def test_linebox_positions():
line-height: 20px }
</style>
<p>this is test for <strong>Weasyprint</strong></p>'''
page, = parse(page % {'fonts': SANS_FONTS, 'width': width})
page, = render_pages(page % {'fonts': SANS_FONTS, 'width': width})
html, = page.children
body, = html.children
paragraph, = body.children
@ -509,7 +508,7 @@ def test_linebox_positions():
def test_forced_line_breaks_pre():
# These lines should be small enough to fit on the default A4 page
# with the default 12pt font-size.
page, = parse('''
page, = render_pages('''
<style> pre { line-height: 42px }</style>
<pre>Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
@ -531,7 +530,7 @@ def test_forced_line_breaks_pre():
@assert_no_logs
def test_forced_line_breaks_paragraph():
page, = parse('''
page, = render_pages('''
<style> p { line-height: 42px }</style>
<p>Lorem ipsum dolor sit amet,<br>
consectetur adipiscing elit.<br><br><br>
@ -555,7 +554,7 @@ def test_inlinebox_splitting():
# The text is strange to test some corner cases
# See https://github.com/Kozea/WeasyPrint/issues/389
for width in [10000, 100, 10, 0]:
page, = parse('''
page, = render_pages('''
<style>p { font-family:%(fonts)s; width: %(width)spx; }</style>
<p><strong>WeasyPrint is a frée softwäre ./ visual rendèring enginè
for HTML !!! and CSS.</strong></p>
@ -581,7 +580,7 @@ def test_inlinebox_splitting():
@assert_no_logs
def test_whitespace_processing():
for source in ['a', ' a ', ' \n \ta', ' a\t ']:
page, = parse('<p><em>%s</em></p>' % source)
page, = render_pages('<p><em>%s</em></p>' % source)
html, = page.children
body, = html.children
p, = body.children
@ -590,7 +589,7 @@ def test_whitespace_processing():
text, = em.children
assert text.text == 'a', 'source was %r' % (source,)
page, = parse(
page, = render_pages(
'<p style="white-space: pre-line">\n\n<em>%s</em></pre>' %
source.replace('\n', ' '))
html, = page.children
@ -604,7 +603,7 @@ def test_whitespace_processing():
@assert_no_logs
def test_inline_replaced_auto_margins():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 200px }
img { display: inline; margin: auto; width: 50px }
@ -622,7 +621,7 @@ def test_inline_replaced_auto_margins():
@assert_no_logs
def test_empty_inline_auto_margins():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 200px }
span { margin: auto }
@ -640,7 +639,7 @@ def test_empty_inline_auto_margins():
@assert_no_logs
def test_font_stretch():
page, = parse('''
page, = render_pages('''
<style>
p { float: left; font-family: %s }
</style>
@ -665,7 +664,7 @@ def test_font_stretch():
('<body style="hyphens: none">hyp&shy;hénation', 1), # … unless disabled
))
def test_line_count(source, lines_count):
page, = parse(
page, = render_pages(
'<html style="width: 5em; font-family: weasyprint">'
'<style>@font-face {'
' src:url(weasyprint.otf); font-family :weasyprint'
@ -683,7 +682,7 @@ def test_vertical_align_1():
# 40px | | | 60px
# | | |
# +-----+-------+ <- baseline
page, = parse('''
page, = render_pages('''
<span>
<img src="pattern.png" style="width: 40px"
><img src="pattern.png" style="width: 60px"
@ -710,7 +709,7 @@ def test_vertical_align_2():
# 40px | | |
# | +-------+ <- baseline
# +-----+ 15px
page, = parse('''
page, = render_pages('''
<span>
<img src="pattern.png" style="width: 40px; vertical-align: -15px"
><img src="pattern.png" style="width: 60px"></span>''')
@ -730,7 +729,7 @@ def test_vertical_align_2():
@assert_no_logs
def test_vertical_align_3():
# Same as previously, but with percentages
page, = parse('''
page, = render_pages('''
<span style="line-height: 10px">
<img src="pattern.png" style="width: 40px; vertical-align: -150%"
><img src="pattern.png" style="width: 60px"></span>''')
@ -750,7 +749,7 @@ def test_vertical_align_3():
@assert_no_logs
def test_vertical_align_4():
# Same again, but have the vertical-align on an inline box.
page, = parse('''
page, = render_pages('''
<span style="line-height: 10px">
<span style="line-height: 10px; vertical-align: -15px">
<img src="pattern.png" style="width: 40px"></span>
@ -772,7 +771,7 @@ def test_vertical_align_4():
@assert_no_logs
def test_vertical_align_5():
# Same as previously, but with percentages
page, = parse(
page, = render_pages(
'<style>'
' @font-face {src: url(weasyprint.otf); font-family: weasyprint}'
'</style>'
@ -800,7 +799,7 @@ def test_vertical_align_5():
def test_vertical_align_6():
# sup and sub currently mean +/- 0.5 em
# With the initial 16px font-size, thats 8px.
page, = parse('''
page, = render_pages('''
<span style="line-height: 10px">
<img src="pattern.png" style="width: 60px"
><img src="pattern.png" style="width: 40px; vertical-align: super"
@ -823,7 +822,7 @@ def test_vertical_align_6():
@assert_no_logs
def test_vertical_align_7():
page, = parse('''
page, = render_pages('''
<body style="line-height: 10px">
<span>
<img src="pattern.png" style="vertical-align: text-top"
@ -847,7 +846,7 @@ def test_vertical_align_8():
# This case used to cause an exception:
# The second span has no children but should count for line heights
# since it has padding.
page, = parse('''<span style="line-height: 1.5">
page, = render_pages('''<span style="line-height: 1.5">
<span style="padding: 1px"></span></span>''')
html, = page.children
body, = html.children
@ -865,7 +864,7 @@ def test_vertical_align_8():
@assert_no_logs
def test_vertical_align_9():
page, = parse('''
page, = render_pages('''
<span>
<img src="pattern.png" style="width: 40px; vertical-align: -15px"
><img src="pattern.png" style="width: 60px"
@ -912,7 +911,7 @@ def test_vertical_align_10():
# The first two images bring the top of the line box 30px above
# the baseline and 10px below.
# Each of the inner span
page, = parse('''
page, = render_pages('''
<span style="font-size: 0">
<img src="pattern.png" style="vertical-align: 26px">
<img src="pattern.png" style="vertical-align: -10px">
@ -945,7 +944,7 @@ def test_vertical_align_10():
@assert_no_logs
def test_vertical_align_11():
page, = parse('''
page, = render_pages('''
<span style="font-size: 0">
<img src="pattern.png" style="vertical-align: bottom">
<img src="pattern.png" style="vertical-align: top; height: 100px">
@ -963,7 +962,7 @@ def test_vertical_align_11():
@assert_no_logs
def test_vertical_align_12():
# Reference for the next test
page, = parse('''
page, = render_pages('''
<span style="font-size: 0; vertical-align: top">
<img src="pattern.png">
</span>
@ -979,7 +978,7 @@ def test_vertical_align_12():
@assert_no_logs
def test_vertical_align_13():
# Should be the same as above
page, = parse('''
page, = render_pages('''
<span style="font-size: 0; vertical-align: top; display: inline-block">
<img src="pattern.png">
</span>''')
@ -996,7 +995,7 @@ def test_vertical_align_13():
@assert_no_logs
def test_box_decoration_break_inline_slice():
# http://www.w3.org/TR/css3-background/#the-box-decoration-break
page_1, = parse('''
page_1, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 100px }
@ -1027,7 +1026,7 @@ def test_box_decoration_break_inline_slice():
@assert_no_logs
def test_box_decoration_break_inline_clone():
# http://www.w3.org/TR/css3-background/#the-box-decoration-break
page_1, = parse('''
page_1, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 100px }

View File

@ -6,13 +6,12 @@
"""
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
def test_inline_block_sizes():
page, = parse('''
page, = render_pages('''
<style>
@page { margin: 0; size: 200px 2000px }
body { margin: 0 }
@ -112,7 +111,7 @@ def test_inline_block_sizes():
@assert_no_logs
def test_inline_block_with_margin():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1235
page_1, = parse('''
page_1, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 100px }

View File

@ -8,8 +8,7 @@
import pytest
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
@ -20,7 +19,7 @@ from ..testing_utils import assert_no_logs
('square', ''),
))
def test_lists_style(inside, style, character):
page, = parse('''
page, = render_pages('''
<style>
body { margin: 0 }
ul { margin-left: 50px; list-style: %s %s }
@ -51,7 +50,7 @@ def test_lists_style(inside, style, character):
def test_lists_empty_item():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/873
page, = parse('''
page, = render_pages('''
<ul>
<li>a</li>
<li></li>
@ -68,7 +67,7 @@ def test_lists_empty_item():
@pytest.mark.xfail
def test_lists_whitespace_item():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/873
page, = parse('''
page, = render_pages('''
<ul>
<li>a</li>
<li> </li>
@ -84,7 +83,7 @@ def test_lists_whitespace_item():
def test_lists_page_break():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/945
page1, page2 = parse('''
page1, page2 = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 300px 100px }

View File

@ -9,8 +9,7 @@
import pytest
from weasyprint.formatting_structure import boxes
from ..test_boxes import render_pages
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
@ -463,7 +462,7 @@ def test_margin_break(break_after, margin_break, margin_top):
@pytest.mark.xfail
@assert_no_logs
def test_margin_break_clearance(): # pragma: no cover
def test_margin_break_clearance():
page_1, page_2 = render_pages('''
<style>
@page { size: 70px; margin: 0 }

View File

@ -6,13 +6,12 @@
"""
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
def test_relative_positioning_1():
page, = parse('''
page, = render_pages('''
<style>
p { height: 20px }
</style>
@ -45,7 +44,7 @@ def test_relative_positioning_1():
@assert_no_logs
def test_relative_positioning_2():
page, = parse('''
page, = render_pages('''
<style>
img { width: 20px }
body { font-size: 0 } /* Remove spaces */
@ -86,7 +85,7 @@ def test_relative_positioning_2():
@assert_no_logs
def test_absolute_positioning_1():
page, = parse('''
page, = render_pages('''
<div style="margin: 3px">
<div style="height: 20px; width: 20px; position: absolute"></div>
<div style="height: 20px; width: 20px; position: absolute;
@ -111,7 +110,7 @@ def test_absolute_positioning_1():
@assert_no_logs
def test_absolute_positioning_2():
page, = parse('''
page, = render_pages('''
<div style="position: relative; width: 20px">
<div style="height: 20px; width: 20px; position: absolute"></div>
<div style="height: 20px; width: 20px"></div>
@ -128,7 +127,7 @@ def test_absolute_positioning_2():
@assert_no_logs
def test_absolute_positioning_3():
page, = parse('''
page, = render_pages('''
<body style="font-size: 0">
<img src=pattern.png>
<span style="position: relative">
@ -150,7 +149,7 @@ def test_absolute_positioning_3():
@assert_no_logs
def test_absolute_positioning_4():
page, = parse('''
page, = render_pages('''
<style> img { width: 5px; height: 20px} </style>
<body style="font-size: 0">
<img src=pattern.png>
@ -168,7 +167,7 @@ def test_absolute_positioning_4():
@assert_no_logs
def test_absolute_positioning_5():
page, = parse('''
page, = render_pages('''
<style> img { width: 5px; height: 20px} </style>
<body style="font-size: 0">
<img src=pattern.png>
@ -186,7 +185,7 @@ def test_absolute_positioning_5():
@assert_no_logs
def test_absolute_positioning_6():
page, = parse('''
page, = render_pages('''
<div style="position: relative; width: 20px; height: 60px;
border: 10px solid; padding-top: 6px; top: 5px; left: 1px">
<div style="height: 20px; width: 20px; position: absolute;
@ -210,7 +209,7 @@ def test_absolute_positioning_6():
@assert_no_logs
def test_absolute_positioning_7():
page, = parse('''
page, = render_pages('''
<style>
@page { size: 1000px 2000px }
html { font-size: 0 }
@ -274,7 +273,7 @@ def test_absolute_positioning_7():
@assert_no_logs
def test_absolute_positioning_8():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1264
page, = parse('''
page, = render_pages('''
<style>@page{ width: 50px; height: 50px }</style>
<body style="font-size: 0">
<div style="position: absolute; margin: auto;
@ -291,7 +290,7 @@ def test_absolute_positioning_8():
@assert_no_logs
def test_absolute_images():
page, = parse('''
page, = render_pages('''
<style>
img { display: block; position: absolute }
</style>
@ -317,7 +316,7 @@ def test_absolute_images():
@assert_no_logs
def test_fixed_positioning():
# TODO:test page-break-before: left/right
page_1, page_2, page_3 = parse('''
page_1, page_2, page_3 = render_pages('''
a
<div style="page-break-before: always; page-break-after: always">
<p style="position: fixed">b</p>
@ -337,7 +336,7 @@ def test_fixed_positioning():
@assert_no_logs
def test_fixed_positioning_regression_1():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/641
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page:first { size: 100px 200px }
@page { size: 200px 100px; margin: 0 }
@ -374,7 +373,7 @@ def test_fixed_positioning_regression_1():
@assert_no_logs
def test_fixed_positioning_regression_2():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/728
page_1, page_2 = parse('''
page_1, page_2 = render_pages('''
<style>
@page { size: 100px 100px }
section { break-after: page }

View File

@ -8,8 +8,7 @@
import pytest
from ..test_boxes import render_pages as parse
from ..testing_utils import assert_no_logs
from ..testing_utils import assert_no_logs, render_pages
@assert_no_logs
@ -17,7 +16,7 @@ from ..testing_utils import assert_no_logs
@pytest.mark.parametrize('font_size', range(1, 10))
def test_shrink_to_fit_floating_point_error_1(margin_left, font_size):
# See bugs #325 and #288, see commit fac5ee9.
page, = parse('''
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 100000px 100px }
@ -37,7 +36,7 @@ def test_shrink_to_fit_floating_point_error_1(margin_left, font_size):
def test_shrink_to_fit_floating_point_error_2(font_size):
letters = 1
while True:
page, = parse('''
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: %d0pt %d0px }

View File

@ -8,9 +8,8 @@
import pytest
from ..test_boxes import render_pages
from ..test_draw import assert_pixels
from ..testing_utils import assert_no_logs, capture_logs
from ..draw import assert_pixels
from ..testing_utils import assert_no_logs, capture_logs, render_pages
@assert_no_logs

View File

@ -12,7 +12,7 @@ import pytest
from PIL import Image
from weasyprint import HTML
from .test_draw import assert_pixels_equal
from .draw import assert_pixels_equal
from .testing_utils import assert_no_logs, capture_logs, resource_filename

View File

@ -22,7 +22,7 @@ from weasyprint import CSS, HTML, __main__, default_url_fetcher
from weasyprint.document import resolve_links
from weasyprint.urls import path2url
from .test_draw import assert_pixels_equal, parse_pixels
from .draw import assert_pixels_equal, parse_pixels
from .testing_utils import (
FakeHTML, assert_no_logs, capture_logs, http_server, resource_filename)

View File

@ -6,129 +6,14 @@
"""
import functools
import pytest
from weasyprint import images
from weasyprint.css import PageType, get_all_computed_styles
from weasyprint.css.counters import CounterStyle
from weasyprint.css.targets import TargetCollector
from weasyprint.formatting_structure import boxes, build
from weasyprint.layout.pages import set_page_type_computed_styles
from .testing_utils import BASE_URL, FakeHTML, assert_no_logs, capture_logs
PROPER_CHILDREN = dict((key, tuple(map(tuple, value))) for key, value in {
# Children can be of *any* type in *one* of the lists.
boxes.BlockContainerBox: [[boxes.BlockLevelBox], [boxes.LineBox]],
boxes.LineBox: [[boxes.InlineLevelBox]],
boxes.InlineBox: [[boxes.InlineLevelBox]],
boxes.TableBox: [[boxes.TableCaptionBox,
boxes.TableColumnGroupBox, boxes.TableColumnBox,
boxes.TableRowGroupBox, boxes.TableRowBox]],
boxes.InlineTableBox: [[boxes.TableCaptionBox,
boxes.TableColumnGroupBox, boxes.TableColumnBox,
boxes.TableRowGroupBox, boxes.TableRowBox]],
boxes.TableColumnGroupBox: [[boxes.TableColumnBox]],
boxes.TableRowGroupBox: [[boxes.TableRowBox]],
boxes.TableRowBox: [[boxes.TableCellBox]],
}.items())
def serialize(box_list):
"""Transform a box list into a structure easier to compare for testing."""
return [(
box.element_tag,
type(box).__name__[:-3],
# All concrete boxes are either text, replaced, column or parent.
(box.text if isinstance(box, boxes.TextBox)
else '<replaced>' if isinstance(box, boxes.ReplacedBox)
else serialize(
getattr(box, 'column_groups', ()) + tuple(box.children))))
for box in box_list]
def _parse_base(html_content, base_url=BASE_URL):
document = FakeHTML(string=html_content, base_url=base_url)
counter_style = CounterStyle()
style_for = get_all_computed_styles(document, counter_style=counter_style)
get_image_from_uri = functools.partial(
images.get_image_from_uri, {}, document.url_fetcher, False)
target_collector = TargetCollector()
return (
document.etree_element, style_for, get_image_from_uri, base_url,
target_collector, counter_style)
def parse(html_content):
"""Parse some HTML, apply stylesheets and transform to boxes."""
box, = build.element_to_box(*_parse_base(html_content))
return box
def parse_all(html_content, base_url=BASE_URL):
"""Like parse() but also run all corrections on boxes."""
box = build.build_formatting_structure(*_parse_base(
html_content, base_url))
_sanity_checks(box)
return box
def render_pages(html_content):
"""Lay out a document and return a list of PageBox objects."""
return [
page._page_box for page in
FakeHTML(string=html_content, base_url=BASE_URL).render().pages]
def assert_tree(box, expected):
"""Check the box tree equality.
The obtained result is prettified in the message in case of failure.
box: a Box object, starting with <html> and <body> blocks.
expected: a list of serialized <body> children as returned by to_lists().
"""
assert box.element_tag == 'html'
assert isinstance(box, boxes.BlockBox)
assert len(box.children) == 1
box = box.children[0]
assert isinstance(box, boxes.BlockBox)
assert box.element_tag == 'body'
assert serialize(box.children) == expected
def _sanity_checks(box):
"""Check that the rules regarding boxes are met.
This is not required and only helps debugging.
- A block container can contain either only block-level boxes or
only line boxes;
- Line boxes and inline boxes can only contain inline-level boxes.
"""
if not isinstance(box, boxes.ParentBox):
return
acceptable_types_lists = None # raises when iterated
for class_ in type(box).mro(): # pragma: no cover
if class_ in PROPER_CHILDREN:
acceptable_types_lists = PROPER_CHILDREN[class_]
break
assert any(
all(isinstance(child, acceptable_types) or
not child.is_in_normal_flow()
for child in box.children)
for acceptable_types in acceptable_types_lists
), (box, box.children)
for child in box.children:
_sanity_checks(child)
from .testing_utils import (
FakeHTML, assert_no_logs, assert_tree, capture_logs, parse, parse_all,
render_pages)
def _get_grid(html):

View File

@ -9,8 +9,7 @@
import pytest
from weasyprint import HTML
from .test_boxes import assert_tree, parse_all, render_pages
from .testing_utils import assert_no_logs
from .testing_utils import assert_no_logs, assert_tree, parse_all, render_pages
@assert_no_logs

View File

@ -9,8 +9,7 @@
import pytest
from weasyprint.formatting_structure import boxes
from .test_boxes import render_pages
from .testing_utils import assert_no_logs
from .testing_utils import assert_no_logs, render_pages
def outer_area(box):

View File

@ -6,8 +6,7 @@
"""
from .test_boxes import render_pages
from .testing_utils import assert_no_logs
from .testing_utils import assert_no_logs, render_pages
@assert_no_logs

View File

@ -312,7 +312,6 @@ def test_links():
assert rects.pop(0) == [0, TOP, 30, TOP - 30]
# 32pt wide (image + 2 * 1pt of border), 20pt high
# TODO: replace these commented tests now that we use named destinations
assert subtypes.pop(0) == b'/Link'
assert b'/Dest (lipsum)' in pdf
link = re.search(

View File

@ -9,9 +9,8 @@
import pytest
from weasyprint.stacking import StackingContext
from .test_boxes import render_pages, serialize
from .test_draw import assert_pixels
from .testing_utils import assert_no_logs
from .draw import assert_pixels
from .testing_utils import assert_no_logs, render_pages, serialize
z_index_source = '''
<style>

View File

@ -10,8 +10,7 @@ import pytest
from weasyprint.css.properties import INITIAL_VALUES
from weasyprint.text.line_break import split_first_line
from .test_boxes import render_pages
from .testing_utils import MONO_FONTS, SANS_FONTS, assert_no_logs
from .testing_utils import MONO_FONTS, SANS_FONTS, assert_no_logs, render_pages
def make_text(text, width=None, **style):

View File

@ -12,7 +12,7 @@ import tempfile
from weasyprint.urls import ensure_url
from .test_draw import assert_pixels_equal, document_to_pixels, html_to_pixels
from .draw import assert_pixels_equal, document_to_pixels, html_to_pixels
from .testing_utils import FakeHTML, assert_no_logs, resource_filename

View File

@ -9,7 +9,7 @@
import pytest
from weasyprint.css.properties import KNOWN_PROPERTIES
from .test_boxes import render_pages as parse
from .testing_utils import render_pages as parse
SIDES = ('top', 'right', 'bottom', 'left')

View File

@ -14,7 +14,11 @@ import sys
import threading
import wsgiref.simple_server
from weasyprint import CSS, HTML
from weasyprint import CSS, HTML, images
from weasyprint.css import get_all_computed_styles
from weasyprint.css.counters import CounterStyle
from weasyprint.css.targets import TargetCollector
from weasyprint.formatting_structure import boxes, build
from weasyprint.logger import LOGGER
from weasyprint.urls import path2url
@ -30,6 +34,22 @@ TEST_UA_STYLESHEET = CSS(filename=os.path.join(
os.path.dirname(__file__), '..', 'weasyprint', 'css', 'tests_ua.css'
))
PROPER_CHILDREN = dict((key, tuple(map(tuple, value))) for key, value in {
# Children can be of *any* type in *one* of the lists.
boxes.BlockContainerBox: [[boxes.BlockLevelBox], [boxes.LineBox]],
boxes.LineBox: [[boxes.InlineLevelBox]],
boxes.InlineBox: [[boxes.InlineLevelBox]],
boxes.TableBox: [[boxes.TableCaptionBox,
boxes.TableColumnGroupBox, boxes.TableColumnBox,
boxes.TableRowGroupBox, boxes.TableRowBox]],
boxes.InlineTableBox: [[boxes.TableCaptionBox,
boxes.TableColumnGroupBox, boxes.TableColumnBox,
boxes.TableRowGroupBox, boxes.TableRowBox]],
boxes.TableColumnGroupBox: [[boxes.TableColumnBox]],
boxes.TableRowGroupBox: [[boxes.TableRowBox]],
boxes.TableRowBox: [[boxes.TableCellBox]],
}.items())
class FakeHTML(HTML):
"""Like weasyprint.HTML, but with a lighter UA stylesheet."""
@ -123,3 +143,99 @@ def http_server(handlers):
finally:
server.shutdown()
thread.join()
def serialize(box_list):
"""Transform a box list into a structure easier to compare for testing."""
return [(
box.element_tag,
type(box).__name__[:-3],
# All concrete boxes are either text, replaced, column or parent.
(box.text if isinstance(box, boxes.TextBox)
else '<replaced>' if isinstance(box, boxes.ReplacedBox)
else serialize(
getattr(box, 'column_groups', ()) + tuple(box.children))))
for box in box_list]
def _parse_base(html_content, base_url=BASE_URL):
document = FakeHTML(string=html_content, base_url=base_url)
counter_style = CounterStyle()
style_for = get_all_computed_styles(document, counter_style=counter_style)
get_image_from_uri = functools.partial(
images.get_image_from_uri, {}, document.url_fetcher, False)
target_collector = TargetCollector()
return (
document.etree_element, style_for, get_image_from_uri, base_url,
target_collector, counter_style)
def parse(html_content):
"""Parse some HTML, apply stylesheets and transform to boxes."""
box, = build.element_to_box(*_parse_base(html_content))
return box
def parse_all(html_content, base_url=BASE_URL):
"""Like parse() but also run all corrections on boxes."""
box = build.build_formatting_structure(*_parse_base(
html_content, base_url))
_sanity_checks(box)
return box
def render_pages(html_content):
"""Lay out a document and return a list of PageBox objects."""
return [
page._page_box for page in
FakeHTML(string=html_content, base_url=BASE_URL).render().pages]
def assert_tree(box, expected):
"""Check the box tree equality.
The obtained result is prettified in the message in case of failure.
box: a Box object, starting with <html> and <body> blocks.
expected: a list of serialized <body> children as returned by to_lists().
"""
assert box.element_tag == 'html'
assert isinstance(box, boxes.BlockBox)
assert len(box.children) == 1
box = box.children[0]
assert isinstance(box, boxes.BlockBox)
assert box.element_tag == 'body'
assert serialize(box.children) == expected
def _sanity_checks(box):
"""Check that the rules regarding boxes are met.
This is not required and only helps debugging.
- A block container can contain either only block-level boxes or
only line boxes;
- Line boxes and inline boxes can only contain inline-level boxes.
"""
if not isinstance(box, boxes.ParentBox):
return
acceptable_types_lists = None # raises when iterated
for class_ in type(box).mro(): # pragma: no cover
if class_ in PROPER_CHILDREN:
acceptable_types_lists = PROPER_CHILDREN[class_]
break
assert any(
all(isinstance(child, acceptable_types) or
not child.is_in_normal_flow()
for child in box.children)
for acceptable_types in acceptable_types_lists
), (box, box.children)
for child in box.children:
_sanity_checks(child)