# coding: utf8 """ weasyprint.tests.test_draw -------------------------- Test the final, drawn results and compare PNG images pixel per pixel. :copyright: Copyright 2011-2012 Simon Sapin and contributors, see AUTHORS. :license: BSD, see LICENSE for details. """ from __future__ import division, unicode_literals import contextlib import os.path import tempfile import shutil import itertools from io import BytesIO import pytest import pystacia from ..compat import xrange, ints_from_bytes from ..urls import ensure_url from .. import HTML, CSS from .testing_utils import ( resource_filename, TestPNGDocument, FONTS, assert_no_logs, capture_logs) # Short variable names are OK here # pylint: disable=C0103 _ = b'\xff\xff\xff\xff' # white r = b'\xff\x00\x00\xff' # red B = b'\x00\x00\xff\xff' # blue BYTES_PER_PIXELS = 4 def assert_pixels(name, expected_width, expected_height, expected_lines, html, nb_pages=1): """Helper testing the size of the image and the pixels values.""" assert len(expected_lines) == expected_height assert len(expected_lines[0]) == expected_width * BYTES_PER_PIXELS expected_raw = b''.join(expected_lines) _doc, lines = html_to_pixels(name, expected_width, expected_height, html, nb_pages=nb_pages) assert_pixels_equal(name, expected_width, expected_height, lines, expected_raw) def assert_same_rendering(expected_width, expected_height, documents): """ Render HTML documents to PNG and check that they render the same, pixel-per-pixel. Each document is passed as a (name, html_source) tuple. """ lines_list = [] for name, html in documents: _doc, lines = html_to_pixels( name, expected_width, expected_height, html) lines_list.append((name, lines)) _name, reference = lines_list[0] for name, lines in lines_list[1:]: assert_pixels_equal(name, expected_width, expected_height, reference, lines) def assert_different_renderings(expected_width, expected_height, documents): """ Render HTML documents to PNG and check that no two documents render the same. Each document is passed as a (name, html_source) tuple. """ lines_list = [] for name, html in documents: _doc, lines = html_to_pixels( name, expected_width, expected_height, html) lines_list.append((name, lines)) for i, (name_1, lines_1) in enumerate(lines_list): for name_2, lines_2 in lines_list[i + 1:]: if lines_1 == lines_2: # pragma: no cover # Same as "assert lines_1 != lines_2" but the output of # the assert hook would be gigantic and useless. assert False, '%s and %s are the same' % (name_1, name_2) def write_png(basename, lines, width, height): # pragma: no cover """Take a pixel matrix and write a PNG file.""" directory = os.path.join(os.path.dirname(__file__), 'test_results') if not os.path.isdir(directory): os.mkdir(directory) filename = os.path.join(directory, basename + '.png') with contextlib.closing(pystacia.read_raw( lines, 'rgba', width, height, depth=8)) as image: image.write(filename) def html_to_pixels(name, expected_width, expected_height, html, nb_pages=1): """ Render an HTML document to PNG, checks its size and return pixel data. Also return the document to aid debugging. """ document = TestPNGDocument(html, # Dummy filename, but in the right directory. base_url=resource_filename('')) lines = document_to_pixels(document, name, expected_width, expected_height, nb_pages=nb_pages) return document, lines def document_to_pixels(document, name, expected_width, expected_height, nb_pages=1): """ Render an HTML document to PNG, checks its size and return pixel data. """ png_bytes = document.write_png() assert len(document.pages) == nb_pages with contextlib.closing(pystacia.read_blob(png_bytes)) as image: assert image.size == (expected_width, expected_height) raw = image.get_raw('rgba')['raw'] assert len(raw) == expected_width * expected_height * BYTES_PER_PIXELS return raw def assert_pixels_equal(name, width, height, raw, expected_raw, tolerance=0): """ Take 2 matrices of height by width pixels and assert that they are the same. """ if raw != expected_raw: # pragma: no cover for i, (value, expected) in enumerate(zip( ints_from_bytes(raw), ints_from_bytes(expected_raw) )): if abs(value - expected) > tolerance: write_png(name, raw, width, height) write_png(name + '.expected', expected_raw, width, height) pixel_n = i // BYTES_PER_PIXELS x = pixel_n // width y = pixel_n % width i % BYTES_PER_PIXELS pixel = tuple(ints_from_bytes(raw[i:i + BYTES_PER_PIXELS])) expected_pixel = tuple(ints_from_bytes( expected_raw[i:i + BYTES_PER_PIXELS])) assert 0, ( 'Pixel (%i, %i) in %s: expected rgba%s, got rgab%s' % (x, y, name, expected_pixel, pixel)) @assert_no_logs def test_canvas_background(): """Test the background applied on ```` and/or ```` tags.""" assert_pixels('all_blue', 10, 10, (10 * [10 * B]), ''' ''') assert_pixels('blocks', 10, 10, [ r+r+r+r+r+r+r+r+r+r, r+r+r+r+r+r+r+r+r+r, r+r+B+B+B+B+B+B+r+r, r+r+B+B+B+B+B+B+r+r, r+r+B+B+B+B+B+B+r+r, r+r+B+B+B+B+B+B+r+r, r+r+B+B+B+B+B+B+r+r, r+r+r+r+r+r+r+r+r+r, r+r+r+r+r+r+r+r+r+r, r+r+r+r+r+r+r+r+r+r, ], ''' ''') @assert_no_logs def test_background_image(): """Test background images.""" # pattern.png looks like this: # r+B+B+B, # B+B+B+B, # B+B+B+B, # B+B+B+B, for name, css, pixels in [ ('repeat', '', [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+r+B+B+B+r+B+B+B+r+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+r+B+B+B+r+B+B+B+r+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+r+B+B+B+r+B+B+B+r+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ]), ('repeat_x', 'repeat-x', [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+r+B+B+B+r+B+B+B+r+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+B+B+B+B+B+B+B+B+B+B+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _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+_+_+_+_+_+_+_+_+_+_+_+_+_, ]), ('fixed_right', 'no-repeat fixed right 3px', [ ####### _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+r+B+_+_, # _+_+_+_+_+_+_+_+_+_+B+B+_+_, # _+_+_+_+_+_+_+_+_+_+B+B+_+_, # _+_+_+_+_+_+_+_+_+_+B+B+_+_, # _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ]), ('fixed_center_center', 'no-repeat fixed 50% center', [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+r+B+B+B+_+_+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ]), ]: assert_pixels('background_' + name, 14, 16, pixels, '''

  ''' % (css,)) @assert_no_logs def test_background_origin(): """Test the background-origin property.""" def test_value(value, pixels, css=None): assert_pixels('background_origin_' + value, 12, 12, pixels, ''' ''' % (css or value,)) test_value('border-box', [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+r+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+_+_+_+_+_, ]) test_value('padding-box', [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+r+B+B+B+_+_, _+_+_+_+_+_+B+B+B+B+_+_, _+_+_+_+_+_+B+B+B+B+_+_, _+_+_+_+_+_+B+B+B+B+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, ]) test_value('content-box', [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+r+B+B+B+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_, _+_+_+_+_+B+B+B+B+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, ]) test_value('border-box_clip', [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+r+B+_+_+_, _+_+_+_+_+_+_+B+B+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, ], css='border-box; background-clip: content-box') @assert_no_logs def test_background_clip(): """Test the background-clip property.""" def test_value(value, pixels): assert_pixels('background_clip_' + value, 8, 8, pixels, ''' ''' % (value,)) test_value('border-box', [ _+_+_+_+_+_+_+_, _+B+B+B+B+B+B+_, _+B+B+B+B+B+B+_, _+B+B+B+B+B+B+_, _+B+B+B+B+B+B+_, _+B+B+B+B+B+B+_, _+B+B+B+B+B+B+_, _+_+_+_+_+_+_+_, ]) test_value('padding-box', [ _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, _+_+B+B+B+B+_+_, _+_+B+B+B+B+_+_, _+_+B+B+B+B+_+_, _+_+B+B+B+B+_+_, _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, ]) test_value('content-box', [ _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, _+_+_+B+B+_+_+_, _+_+_+B+B+_+_+_, _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_, ]) @assert_no_logs def test_background_size(): """Test the background-size property.""" assert_pixels('background_size', 12, 12, [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+r+r+B+B+B+B+B+B+_, _+_+_+r+r+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+B+B+B+B+B+B+B+B+_, _+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') assert_pixels('background_size_auto', 12, 12, [ _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+r+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') assert_pixels('background_size_contain', 14, 10, [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+r+r+B+B+B+B+B+B+_+_+_+_+_, _+r+r+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') assert_pixels('background_size_mixed', 14, 10, [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+r+r+B+B+B+B+B+B+_+_+_+_+_, _+r+r+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') assert_pixels('background_size_double', 14, 10, [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+r+r+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+B+B+B+B+B+B+B+B+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') assert_pixels('background_size_cover', 14, 10, [ _+_+_+_+_+_+_+_+_+_+_+_+_+_, _+r+r+r+B+B+B+B+B+B+B+B+B+_, _+r+r+r+B+B+B+B+B+B+B+B+B+_, _+r+r+r+B+B+B+B+B+B+B+B+B+_, _+B+B+B+B+B+B+B+B+B+B+B+B+_, _+B+B+B+B+B+B+B+B+B+B+B+B+_, _+B+B+B+B+B+B+B+B+B+B+B+B+_, _+B+B+B+B+B+B+B+B+B+B+B+B+_, _+B+B+B+B+B+B+B+B+B+B+B+B+_, _+_+_+_+_+_+_+_+_+_+_+_+_+_, ], ''' ''') @assert_no_logs def test_list_style_image(): """Test images as list markers.""" for position, pixels in [ ('outside', [ # ++++++++++++++ ++++

  • horizontal margins: 7px 2px # ######
  • width: 12 - 7 - 2 = 3px # -- list marker margin: 0.5em = 2px # ******** list marker image is 4px wide _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+r+B+B+B+_+_+_+_+_+_, _+_+B+B+B+B+_+_+_+_+_+_, _+_+B+B+B+B+_+_+_+_+_+_, _+_+B+B+B+B+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, ]), ('inside', [ # ++++++++++++++ ++++
  • horizontal margins: 7px 2px # ######
  • width: 12 - 7 - 2 = 3px # ******** list marker image is 4px wide: overflow _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+r+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+B+B+B+B+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_+_+_, ]) ]: assert_pixels('list_style_image_' + position, 12, 10, pixels, ''' ''' % (FONTS, position)) assert_pixels('list_style_none', 10, 10, [ _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, _+_+_+_+_+_+_+_+_+_, ], '''