Skip to content

Failing some test_text tests #1535

@jtojnar

Description

@jtojnar

When building WeasyPrint 54.0 in Nix, the following tests fail:

=================================== FAILURES ===================================
_____________________________ test_tab_size[8-144] _____________________________

value = 8, width = 144

    @assert_no_logs
    @pytest.mark.parametrize('value, width', (
        (8, 144),  # (2 + (8 - 1)) * 16
        (4, 80),  # (2 + (4 - 1)) * 16
        ('3em', 64),  # (2 + (3 - 1)) * 16
        ('25px', 41),  # 2 * 16 + 25 - 1 * 16
        # (0, 32),  # See Layout.set_tabs
    ))
    def test_tab_size(value, width):
        page, = render_pages('''
          <style>
            @font-face {src: url(weasyprint.otf); font-family: weasyprint}
            pre { tab-size: %s; font-family: weasyprint }
          </style>
          <pre>a&#9;a</pre>
        ''' % value)
        html, = page.children
        body, = html.children
        paragraph, = body.children
        line, = paragraph.children
>       assert line.width == width
E       assert 160.0 == 144
E        +  where 160.0 = <LineBox pre>.width

/build/weasyprint-54.0/tests/test_text.py:1167: AssertionError
------------------------------ Captured log call -------------------------------
INFO     weasyprint.progress:__init__.py:77 Step 1 - Fetching and parsing HTML - HTML string
INFO     weasyprint.progress:__init__.py:210 Step 2 - Fetching and parsing CSS - CSS string
INFO     weasyprint.progress:__init__.py:65 Step 3 - Applying CSS
INFO     weasyprint.progress:document.py:903 Step 4 - Creating formatting structure
INFO     weasyprint.progress:page.py:844 Step 5 - Creating layout - Page 1
_____________________________ test_tab_size[4-80] ______________________________

value = 4, width = 80

    @assert_no_logs
    @pytest.mark.parametrize('value, width', (
        (8, 144),  # (2 + (8 - 1)) * 16
        (4, 80),  # (2 + (4 - 1)) * 16
        ('3em', 64),  # (2 + (3 - 1)) * 16
        ('25px', 41),  # 2 * 16 + 25 - 1 * 16
        # (0, 32),  # See Layout.set_tabs
    ))
    def test_tab_size(value, width):
        page, = render_pages('''
          <style>
            @font-face {src: url(weasyprint.otf); font-family: weasyprint}
            pre { tab-size: %s; font-family: weasyprint }
          </style>
          <pre>a&#9;a</pre>
        ''' % value)
        html, = page.children
        body, = html.children
        paragraph, = body.children
        line, = paragraph.children
>       assert line.width == width
E       assert 96.0 == 80
E        +  where 96.0 = <LineBox pre>.width

/build/weasyprint-54.0/tests/test_text.py:1167: AssertionError
------------------------------ Captured log call -------------------------------
INFO     weasyprint.progress:__init__.py:77 Step 1 - Fetching and parsing HTML - HTML string
INFO     weasyprint.progress:__init__.py:210 Step 2 - Fetching and parsing CSS - CSS string
INFO     weasyprint.progress:__init__.py:65 Step 3 - Applying CSS
INFO     weasyprint.progress:document.py:903 Step 4 - Creating formatting structure
INFO     weasyprint.progress:page.py:844 Step 5 - Creating layout - Page 1
____________________________ test_tab_size[3em-64] _____________________________

value = '3em', width = 64

    @assert_no_logs
    @pytest.mark.parametrize('value, width', (
        (8, 144),  # (2 + (8 - 1)) * 16
        (4, 80),  # (2 + (4 - 1)) * 16
        ('3em', 64),  # (2 + (3 - 1)) * 16
        ('25px', 41),  # 2 * 16 + 25 - 1 * 16
        # (0, 32),  # See Layout.set_tabs
    ))
    def test_tab_size(value, width):
        page, = render_pages('''
          <style>
            @font-face {src: url(weasyprint.otf); font-family: weasyprint}
            pre { tab-size: %s; font-family: weasyprint }
          </style>
          <pre>a&#9;a</pre>
        ''' % value)
        html, = page.children
        body, = html.children
        paragraph, = body.children
        line, = paragraph.children
>       assert line.width == width
E       assert 80.0 == 64
E        +  where 80.0 = <LineBox pre>.width

/build/weasyprint-54.0/tests/test_text.py:1167: AssertionError
------------------------------ Captured log call -------------------------------
INFO     weasyprint.progress:__init__.py:77 Step 1 - Fetching and parsing HTML - HTML string
INFO     weasyprint.progress:__init__.py:210 Step 2 - Fetching and parsing CSS - CSS string
INFO     weasyprint.progress:__init__.py:65 Step 3 - Applying CSS
INFO     weasyprint.progress:document.py:903 Step 4 - Creating formatting structure
INFO     weasyprint.progress:page.py:844 Step 5 - Creating layout - Page 1
____________________________ test_tab_size[25px-41] ____________________________

value = '25px', width = 41

    @assert_no_logs
    @pytest.mark.parametrize('value, width', (
        (8, 144),  # (2 + (8 - 1)) * 16
        (4, 80),  # (2 + (4 - 1)) * 16
        ('3em', 64),  # (2 + (3 - 1)) * 16
        ('25px', 41),  # 2 * 16 + 25 - 1 * 16
        # (0, 32),  # See Layout.set_tabs
    ))
    def test_tab_size(value, width):
        page, = render_pages('''
          <style>
            @font-face {src: url(weasyprint.otf); font-family: weasyprint}
            pre { tab-size: %s; font-family: weasyprint }
          </style>
          <pre>a&#9;a</pre>
        ''' % value)
        html, = page.children
        body, = html.children
        paragraph, = body.children
        line, = paragraph.children
>       assert line.width == width
E       assert 57.0 == 41
E        +  where 57.0 = <LineBox pre>.width

/build/weasyprint-54.0/tests/test_text.py:1167: AssertionError
------------------------------ Captured log call -------------------------------
INFO     weasyprint.progress:__init__.py:77 Step 1 - Fetching and parsing HTML - HTML string
INFO     weasyprint.progress:__init__.py:210 Step 2 - Fetching and parsing CSS - CSS string
INFO     weasyprint.progress:__init__.py:65 Step 3 - Applying CSS
INFO     weasyprint.progress:document.py:903 Step 4 - Creating formatting structure
INFO     weasyprint.progress:page.py:844 Step 5 - Creating layout - Page 1
__________________________ test_tabulation_character ___________________________

    def test_tabulation_character():
        # Test regression: https://github.com/Kozea/WeasyPrint/issues/1515
>       assert_pixels('zero_width_character', 10, 4, '''
            __________
            _RR____RR_
            _RR____RR_
            __________
        ''', '''
          <style>
            @font-face {src: url(weasyprint.otf); font-family: weasyprint}
            @page {
              size: 10px 4px;
              background: white;
              margin: 1px;
            }
            body {
              color: red;
              font-family: weasyprint;
              font-size: 2px;
              line-height: 1;
              tab-size: 3;
            }
          </style>
          <pre>a&Tab;b</pre>''')

/build/weasyprint-54.0/tests/draw/test_text.py:565: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/build/weasyprint-54.0/tests/draw/__init__.py:53: in assert_pixels
    assert_pixels_equal(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

name = 'zero_width_character', width = 10, height = 4
raw = <ImagingCore object at 0x7ffff1c70b50>
expected_raw = [(255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), (255, 255, 255), ...]
tolerance = 0

    def assert_pixels_equal(name, width, height, raw, expected_raw, tolerance=0):
        """Take 2 matrices of pixels and assert that they are the same."""
        if raw != expected_raw:  # pragma: no cover
            pixels = zip_longest(raw, expected_raw, fillvalue=(-1, -1, -1))
            for i, (value, expected) in enumerate(pixels):
                if expected is None:
                    continue
                if any(abs(value - expected) > tolerance
                       for value, expected in zip(value, expected)):
                    actual_height = len(raw) // width
                    write_png(name, raw, width, actual_height)
                    expected_raw = [
                        pixel or (255, 255, 255) for pixel in expected_raw]
                    write_png(name + '.expected', expected_raw, width, height)
                    x = i % width
                    y = i // width
>                   assert 0, (
                        f'Pixel ({x}, {y}) in {name}: '
                        f'expected rgba{expected}, got rgba{value}')
E                   AssertionError: Pixel (7, 1) in zero_width_character: expected rgba(255, 0, 0), got rgba(255, 255, 255)

/build/weasyprint-54.0/tests/draw/__init__.py:146: AssertionError
------------------------------ Captured log call -------------------------------
INFO     weasyprint.progress:__init__.py:77 Step 1 - Fetching and parsing HTML - HTML string
INFO     weasyprint.progress:__init__.py:210 Step 2 - Fetching and parsing CSS - CSS string
INFO     weasyprint.progress:__init__.py:65 Step 3 - Applying CSS
INFO     weasyprint.progress:document.py:903 Step 4 - Creating formatting structure
INFO     weasyprint.progress:page.py:844 Step 5 - Creating layout - Page 1
INFO     weasyprint.progress:document.py:1132 Step 6 - Creating PDF
INFO     weasyprint.progress:document.py:1288 Step 7 - Adding PDF metadata
=============================== warnings summary ===============================
../../nix/store/5fism0m4a19lqla9nx6i58fzfkr318yk-python3.9-fonttools-4.26.2/lib/python3.9/site-packages/fontTools/misc/py23.py:11
  /nix/store/5fism0m4a19lqla9nx6i58fzfkr318yk-python3.9-fonttools-4.26.2/lib/python3.9/site-packages/fontTools/misc/py23.py:11: DeprecationWarning: The py23 module has been deprecated and will be removed in a future release. Please update your code.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
FAILED tests/test_text.py::test_tab_size[8-144] - assert 160.0 == 144
FAILED tests/test_text.py::test_tab_size[4-80] - assert 96.0 == 80
FAILED tests/test_text.py::test_tab_size[3em-64] - assert 80.0 == 64
FAILED tests/test_text.py::test_tab_size[25px-41] - assert 57.0 == 41
FAILED tests/draw/test_text.py::test_tabulation_character - AssertionError: P...
= 5 failed, 1578 passed, 1 deselected, 31 xfailed, 1 warning in 87.42s (0:01:27) =

In 53.4, the same tests were failing (except for tests/draw/test_text.py::test_tabulation_character, which did not exist).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions