Skip to content

Commit

Permalink
Merge pull request #594 from Kozea/test
Browse files Browse the repository at this point in the history
Clean tests
  • Loading branch information
liZe authored Mar 21, 2018
2 parents 043dcc1 + dafed64 commit bb9592d
Show file tree
Hide file tree
Showing 57 changed files with 10,286 additions and 9,593 deletions.
4 changes: 0 additions & 4 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ exclude_lines =
def __repr__
raise NotImplementedError
omit =
weasyprint/tests/test_web/*
weasyprint/tests/w3_test_suite/*
*/virtualenv/*
*/.virtualenvs/*
.*
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
# Tests
/.pytest_cache
/weasyprint/tests/.cache
/weasyprint/tests/test_results
/weasyprint/tests/w3_test_suite/test_results
/weasyprint/tests/test_draw/results
4 changes: 2 additions & 2 deletions docs/hacking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ The website version is updated automatically when we push to master on GitHub.
Code changes
------------

Use the ``pytest`` command from the ``WeasyPrint`` directory to run the
test suite.
Use the ``python setup.py test`` command from the ``WeasyPrint`` directory to
run the test suite.

Please report any bugs/feature requests and submit patches/pull requests
`on Github <https://github.com/Kozea/WeasyPrint>`_.
Expand Down
20 changes: 13 additions & 7 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ WeasyPrint |version| depends on:


Python, cairo, Pango and GDK-PixBuf need to be installed separately. See
platform-specific instructions for :ref:`Linux <linux>`, :ref:`OS X <os-x>` and
:ref:`Windows <windows>` below.
platform-specific instructions for :ref:`Linux <linux>`, :ref:`macOS <macos>`
and :ref:`Windows <windows>` below.

Install WeasyPrint with pip_.
This will automatically install most of dependencies.
Expand All @@ -57,13 +57,19 @@ Now let’s try it:
You should see warnings about unsupported CSS 3 stuff; this is expected.
In the PDF you should see the WeasyPrint logo on the first page.

You can also play with :ref:`navigator`. Start it with
You can also play with :ref:`navigator` or :ref:`renderer`. Start it with

.. code-block:: sh
python -m weasyprint.navigator
python -m weasyprint.tools.navigator
and open your browser at http://127.0.0.1:5000/. Read more :ref:`in the tutorial <navigator>`.
or

.. code-block:: sh
python -m weasyprint.tools.renderer
and open your browser at http://127.0.0.1:5000/.

If everything goes well, you’re ready to :doc:`start using </tutorial>`
WeasyPrint! Otherwise, please copy the full error message and
Expand Down Expand Up @@ -136,8 +142,8 @@ install it with pip after installing the following packages:
emerge pip cairo pango gdk-pixbuf cffi
OS X
----
macOS
-----

WeasyPrint is automatically installed and tested on virtual macOS machines. The
official installation method relies on Homebrew:
Expand Down
32 changes: 28 additions & 4 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,26 @@ these logs, you can for example use a filter:
See the documentation of the :mod:`logging` module for details.


WeasyPrint Tools
----------------

WeasyPrint provides two very limited tools, helping users to play with
WeasyPrint, test it, and understand how to use it as a library.

These tools are just "toys" and are not intended to be significantly improved
in the future.

.. _navigator:

WeasyPrint Navigator
--------------------
....................

*WeasyPrint Navigator* is a very limited web browser, running
in your web browser. Start it with:
*WeasyPrint Navigator* is a web browser running in your web browser. Start it
with:

.. code-block:: sh
python -m weasyprint.navigator
python -m weasyprint.tools.navigator
… and open your browser at http://127.0.0.1:5000/.

Expand All @@ -286,6 +295,21 @@ It does not support cookies, forms, or many other things that you would
expect from a “real” browser. It only shows the PNG output from WeasyPrint
with overlaid clickable hyperlinks. It is mostly useful for playing and testing.

.. _renderer:

WeasyPrint Renderer
...................

*WeasyPrint Renderer* is a web app providing on the same web page a textarea
where you can type an HTML/CSS document, and this document rendered by
WeasyPrint as a PNG image. Start it with:

.. code-block:: sh
python -m weasyprint.tools.renderer
… and open your browser at http://127.0.0.1:5000/.


Errors
------
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ build-dir = docs/_build
test = pytest

[tool:pytest]
addopts = --cov=weasyprint --flake8 --isort
norecursedirs = dist .cache .git build *.egg-info .eggs venv
addopts = --cov --flake8 --isort
norecursedirs = build dist .cache .eggs .git
4 changes: 1 addition & 3 deletions weasyprint/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
'Make sure it is not imported before WeasyPrint.')


CAIRO_HAS_MIME_DATA = cairocffi.cairo_version() >= 11000

# Map values of the image-rendering property to cairo FILTER values:
# Values are normalized to lower case.
IMAGE_RENDERING_TO_FILTER = {
Expand Down Expand Up @@ -218,7 +216,7 @@ def get_image_from_uri(cache, url_fetcher, url, forced_mime_type=None):
pixbuf.decode_to_image_surface(string))
except pixbuf.ImageLoadingError as exception:
raise ImageLoadingError(str(exception))
if format_name == 'jpeg' and CAIRO_HAS_MIME_DATA:
if format_name == 'jpeg':
surface.set_mime_data('image/jpeg', string)
image = RasterImage(surface)
except (URLFetchingError, ImageLoadingError) as exc:
Expand Down
39 changes: 39 additions & 0 deletions weasyprint/tests/test_acid2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
weasyprint.tests.test_draw.test_acid2
-------------------------------------
Check the famous Acid2 test.
:copyright: Copyright 2011-2018 Simon Sapin and contributors, see AUTHORS.
:license: BSD, see LICENSE for details.
"""

from .. import HTML
from .test_draw import assert_pixels_equal, image_to_pixels
from .testing_utils import (
assert_no_logs, capture_logs, requires, resource_filename)


@assert_no_logs
@requires('cairo', (1, 12, 0))
def test_acid2():
def render(filename):
return HTML(resource_filename(filename)).render(enable_hinting=True)

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
test_image, width, height = document.copy(
[test_page]).write_image_surface()

# This is a copy of http://www.webstandards.org/files/acid2/reference.html
ref_image, ref_width, ref_height = render(
'acid2-reference.html').write_image_surface()

assert (width, height) == (ref_width, ref_height)
assert_pixels_equal(
'acid2', width, height, image_to_pixels(test_image, width, height),
image_to_pixels(ref_image, width, height), tolerance=2)
Loading

0 comments on commit bb9592d

Please sign in to comment.