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

42 lines
1.2 KiB
Python
Raw Normal View History

2018-03-20 01:35:56 +03:00
"""
weasyprint.tests.test_draw.test_acid2
-------------------------------------
Check the famous Acid2 test.
"""
import io
2020-12-11 01:05:44 +03:00
import pytest
from PIL import Image
2020-12-06 22:19:59 +03:00
from weasyprint import HTML
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):
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)