2022-03-25 13:47:27 +03:00
|
|
|
"""Check the famous Acid2 test."""
|
2018-03-20 01:35:56 +03:00
|
|
|
|
2020-05-18 01:48:43 +03:00
|
|
|
import io
|
|
|
|
|
2020-12-11 01:05:44 +03:00
|
|
|
import pytest
|
2020-05-18 01:48:43 +03:00
|
|
|
from PIL import Image
|
2020-12-06 22:19:59 +03:00
|
|
|
from weasyprint import HTML
|
2020-05-18 01:48:43 +03:00
|
|
|
|
2021-04-19 18:15:53 +03:00
|
|
|
from .draw import assert_pixels_equal
|
2020-05-16 01:25:11 +03:00
|
|
|
from .testing_utils import assert_no_logs, capture_logs, resource_filename
|
2018-03-20 01:35:56 +03:00
|
|
|
|
|
|
|
|
2020-12-11 01:05:44 +03:00
|
|
|
@pytest.mark.xfail
|
2018-03-20 01:35:56 +03:00
|
|
|
@assert_no_logs
|
|
|
|
def test_acid2():
|
2020-12-11 01:05:44 +03:00
|
|
|
# TODO: fails because of Ghostscript rendering
|
2018-03-20 01:35:56 +03:00
|
|
|
def render(filename):
|
2020-04-18 01:19:35 +03:00
|
|
|
return HTML(resource_filename(filename)).render()
|
2018-03-20 01:35:56 +03:00
|
|
|
|
|
|
|
with capture_logs():
|
|
|
|
# This is a copy of http://www.webstandards.org/files/acid2/test.html
|
|
|
|
document = render('acid2-test.html')
|
|
|
|
intro_page, test_page = document.pages
|
|
|
|
# Ignore the intro page: it is not in the reference
|
2020-05-18 02:36:48 +03:00
|
|
|
test_png = document.copy([test_page]).write_png()
|
|
|
|
test_pixels = Image.open(io.BytesIO(test_png)).getdata()
|
2018-03-20 01:35:56 +03:00
|
|
|
|
|
|
|
# This is a copy of http://www.webstandards.org/files/acid2/reference.html
|
2020-05-18 02:36:48 +03:00
|
|
|
ref_png = render('acid2-reference.html').write_png()
|
|
|
|
ref_image = Image.open(io.BytesIO(ref_png))
|
|
|
|
ref_pixels = ref_image.getdata()
|
|
|
|
width, height = ref_image.size
|
2018-03-20 01:35:56 +03:00
|
|
|
|
|
|
|
assert_pixels_equal(
|
2020-05-18 02:36:48 +03:00
|
|
|
'acid2', width, height, test_pixels, ref_pixels, tolerance=2)
|