Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_gradient.py fails for i586 #913

Closed
pgajdos opened this issue Jul 29, 2019 · 14 comments

Comments

@pgajdos
Copy link

commented Jul 29, 2019

[  114s] /home/abuild/rpmbuild/BUILD/WeasyPrint-48/weasyprint/tests/test_draw/__init__.py:60: in assert_pixels
[  114s]     name, expected_width, expected_height, pixels, expected_raw)
[  114s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[  114s] 
[  114s] name = 'linear_gradient', width = 9, height = 5
[  114s] raw = b'\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f...7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff\x7f\x00\x7f\xff'
[  114s] expected_raw = b'\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80...80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff\x80\x00\x80\xff'
[  114s] tolerance = 0
[  114s] 
[  114s]     def assert_pixels_equal(name, width, height, raw, expected_raw, tolerance=0):
[  114s]         """Take 2 matrices of pixels and assert that they are the same."""
[  114s]         if raw != expected_raw:  # pragma: no cover
[  114s]             for i, (value, expected) in enumerate(zip(raw, expected_raw)):
[  114s]                 if abs(value - expected) > tolerance:
[  114s]                     write_png(name, raw, width, height)
[  114s]                     write_png(name + '.expected', expected_raw,
[  114s]                               width, height)
[  114s]                     pixel_n = i // 4
[  114s]                     x = pixel_n // width
[  114s]                     y = pixel_n % width
[  114s]                     i % 4
[  114s]                     pixel = tuple(list(raw[i:i + 4]))
[  114s]                     expected_pixel = tuple(list(
[  114s]                         expected_raw[i:i + 4]))
[  114s]                     assert 0, (
[  114s]                         'Pixel (%i, %i) in %s: expected rgba%s, got rgba%s'
[  114s] >                       % (x, y, name, expected_pixel, pixel))
[  114s] E                   AssertionError: Pixel (0, 0) in linear_gradient: expected rgba(128, 0, 128, 255), got rgba(127, 0, 127, 255)
[  114s] 
[  114s] /home/abuild/rpmbuild/BUILD/WeasyPrint-48/weasyprint/tests/test_draw/__init__.py:164: AssertionError
[  114s] ------------------------------ Captured log call -------------------------------
[  114s] INFO     weasyprint.progress:__init__.py:109 Step 1 - Fetching and parsing HTML - HTML string
[  114s] INFO     weasyprint.progress:__init__.py:317 Step 2 - Fetching and parsing CSS - CSS string
[  114s] INFO     weasyprint.progress:__init__.py:66 Step 3 - Applying CSS
[  114s] INFO     weasyprint.progress:document.py:369 Step 4 - Creating formatting structure
[  114s] INFO     weasyprint.progress:pages.py:791 Step 5 - Creating layout - Page 1
[  114s] INFO     weasyprint.progress:document.py:734 Step 6 - Drawing
[  114s] =============================== warnings summary ===============================

Tested with 46, 47 and 48.

Let me know if I can help somehow.

@pgajdos

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

(it is test_linear_gradients_7)

@pgajdos

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

This is with python 3.7.

@liZe

This comment has been minimized.

Copy link
Member

commented Jul 29, 2019

Thank you for this issue.

What's your version of Cairo?

@pgajdos

This comment has been minimized.

Copy link
Author

commented Jul 30, 2019

Cairo version is 1.16.0. Here is full build log.

@liZe

This comment has been minimized.

Copy link
Member

commented Jul 30, 2019

It's a test that should return a square with one color: a mix of red and blue. The test on the platforms I use give #800080 (on Windows, MacOS and Linux, I suppose i686), while on your platform it gives #7F007F.

There's probably a difference in Cairo about optimizations depending on the platform, and the output is so close that it's tolerated. You can safely ignore this failing test.

If it's important for you to have this test passing (I don't know why you launch tests on i586 😄), we can try to find a solution.

@Tontyna

This comment has been minimized.

Copy link
Contributor

commented Jul 30, 2019

My platform, too, gives #7f007f
Windows 7 64bit, Cairo 1.16.0

@liZe

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

If it's important for you to have this test passing (I don't know why you launch tests on i586), we can try to find a solution.

@pgajdos Is there a way for you to ignore that test?

@pgajdos

This comment has been minimized.

Copy link
Author

commented Aug 21, 2019

Sure.

@liZe

This comment has been minimized.

Copy link
Member

commented Aug 21, 2019

This test is useful, I'd like to keep it. We can try to find other values that work the same way everywhere.

@pgajdos @Tontyna Does this test pass for you?

@assert_no_logs
@requires('cairo', (1, 14, 0))
def test_linear_gradients_7():
    assert_pixels('linear_gradient', 9, 5, '''
        ggggggggg
        ggggggggg
        ggggggggg
        ggggggggg
        ggggggggg
    ''', '''<style>@page { size: 9px 5px; background: repeating-linear-gradient(
      to right, black 3px, black 3px, lime 3px, lime 3px
    )''')
@pgajdos

This comment has been minimized.

Copy link
Author

commented Aug 21, 2019

With the above, I get for i586:

[   64s] =================================== FAILURES ===================================
[   64s] ___________________________ test_linear_gradients_7 ____________________________
[   64s] 
[   64s]     @assert_no_logs
[   64s]     @requires('cairo', (1, 14, 0))
[   64s]     def test_linear_gradients_7():
[   64s]         assert_pixels('linear_gradient', 9, 5, '''
[   64s]             ggggggggg
[   64s]             ggggggggg
[   64s]             ggggggggg
[   64s]             ggggggggg
[   64s]             ggggggggg
[   64s]         ''', '''<style>@page { size: 9px 5px; background: repeating-linear-gradient(
[   64s]           to right, black 3px, black 3px, lime 3px, lime 3px
[   64s] >       )''')
[   64s] 
[   64s] /home/abuild/rpmbuild/BUILD/WeasyPrint-48/weasyprint/tests/test_draw/test_gradient.py:119: 
[   64s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   64s] /home/abuild/rpmbuild/BUILD/WeasyPrint-48/weasyprint/tests/test_draw/__init__.py:60: in assert_pixels
[   64s]     name, expected_width, expected_height, pixels, expected_raw)
[   64s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[   64s] 
[   64s] name = 'linear_gradient', width = 9, height = 5
[   64s] raw = b'\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00...00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff\x00\x7f\x00\xff'
[   64s] expected_raw = b'\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00...00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff\x00\x80\x00\xff'
[   64s] tolerance = 0
[   64s] 
[   64s]     def assert_pixels_equal(name, width, height, raw, expected_raw, tolerance=0):
[   64s]         """Take 2 matrices of pixels and assert that they are the same."""
[   64s]         if raw != expected_raw:  # pragma: no cover
[   64s]             for i, (value, expected) in enumerate(zip(raw, expected_raw)):
[   64s]                 if abs(value - expected) > tolerance:
[   64s]                     write_png(name, raw, width, height)
[   64s]                     write_png(name + '.expected', expected_raw,
[   64s]                               width, height)
[   64s]                     pixel_n = i // 4
[   64s]                     x = pixel_n // width
[   64s]                     y = pixel_n % width
[   64s]                     i % 4
[   64s]                     pixel = tuple(list(raw[i:i + 4]))
[   64s]                     expected_pixel = tuple(list(
[   64s]                         expected_raw[i:i + 4]))
[   64s]                     assert 0, (
[   64s]                         'Pixel (%i, %i) in %s: expected rgba%s, got rgba%s'
[   64s] >                       % (x, y, name, expected_pixel, pixel))
[   64s] E                   AssertionError: Pixel (0, 0) in linear_gradient: expected rgba(128, 0, 255, 0), got rgba(127, 0, 255, 0)
[   64s] 
[   64s] /home/abuild/rpmbuild/BUILD/WeasyPrint-48/weasyprint/tests/test_draw/__init__.py:164: AssertionError
[   64s] ------------------------------ Captured log call -------------------------------
[   64s] INFO     weasyprint.progress:__init__.py:109 Step 1 - Fetching and parsing HTML - HTML string
[   64s] INFO     weasyprint.progress:__init__.py:317 Step 2 - Fetching and parsing CSS - CSS string
[   64s] INFO     weasyprint.progress:__init__.py:66 Step 3 - Applying CSS
[   64s] INFO     weasyprint.progress:document.py:369 Step 4 - Creating formatting structure
[   64s] INFO     weasyprint.progress:pages.py:791 Step 5 - Creating layout - Page 1
[   64s] INFO     weasyprint.progress:document.py:734 Step 6 - Drawing
[   64s] =============================== warnings summary ===============================
[   64s] /usr/lib/python3.7/site-packages/html5lib/_trie/_base.py:3
[   64s]   /usr/lib/python3.7/site-packages/html5lib/_trie/_base.py:3: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
[   64s]     from collections import Mapping
[   64s] 
[   64s] -- Docs: https://docs.pytest.org/en/latest/warnings.html
[   64s] ========= 1 failed, 949 passed, 7 xfailed, 1 warnings in 26.69 seconds =========
@pgajdos

This comment has been minimized.

Copy link
Author

commented Aug 21, 2019

It succeedes for x86_64.

@liZe

This comment has been minimized.

Copy link
Member

commented Aug 21, 2019

Then I'm afraid I can't do anything. If you can find a value that works with both i586 and x86_64, I'll be happy to use it, but otherwise you'll have to skip this test 😢.

@Tontyna

This comment has been minimized.

Copy link
Contributor

commented Aug 21, 2019

The truth (and the mystery) is:

  • when rendered as PDF my platform produces #7f007f
  • when rendered as PNG my platform produces #800080. That's why the gradient unit tests succeed

Yes, I know, these are different Cairo surfaces. Cannot detect a/the relationship between the processor architecture and the cairo_image_surface in the Cairo source.
Maybe this time it's not Cairo but ... the Cairo PNG functionality depends afaik on libpng

@liZe

This comment has been minimized.

Copy link
Member

commented Sep 3, 2019

It's hard to decide if the color between #ff00ff and #000000 is #800080 or #7f007f. It's actually between, isn't it? The problem is not technical, it's just logical.

We can solve this by using a color whose hexadecimal components are even. For example, using #800080 and #000000 would give #400040.

@liZe liZe closed this in fb62571 Sep 3, 2019

@liZe liZe added this to the 49 milestone Sep 3, 2019

@liZe liZe added the bug label Sep 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.