File: test_overflow.py

package info (click to toggle)
weasyprint 62.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,964 kB
  • sloc: python: 54,652; makefile: 12
file content (204 lines) | stat: -rw-r--r-- 4,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
"""Test overflow and clipping."""

import pytest

from ..testing_utils import assert_no_logs


@assert_no_logs
def test_overflow_1(assert_pixels):
    # See test_images
    assert_pixels('''
        ________
        ________
        __rBBB__
        __BBBB__
        ________
        ________
        ________
        ________
    ''', '''
      <style>
        @page { size: 8px }
        body { margin: 2px 0 0 2px; font-size: 0 }
        div { height: 2px; overflow: hidden }
      </style>
      <div><img src="pattern.png"></div>''')


@assert_no_logs
def test_overflow_2(assert_pixels):
    # <body> is only 1px high, but its overflow is propageted to the viewport
    # ie. the padding edge of the page box.
    assert_pixels('''
        ________
        ________
        __rBBB__
        __BBBB__
        __BBBB__
        ________
        ________
        ________
    ''', '''
      <style>
        @page { size: 8px; margin: 2px 2px 3px 2px }
        body { height: 1px; overflow: hidden; font-size: 0 }
      </style>
      <div><img src="pattern.png"></div>''')


@assert_no_logs
def test_overflow_3(assert_pixels):
    # Assert that the border is not clipped by overflow: hidden
    assert_pixels('''
        ________
        ________
        __BBBB__
        __B__B__
        __B__B__
        __BBBB__
        ________
        ________
    ''', '''
      <style>
        @page { size: 8px; margin: 2px; }
        div { width: 2px; height: 2px; overflow: hidden;
              border: 1px solid blue; }
      </style>
      <div></div>''')


@assert_no_logs
def test_overflow_4(assert_pixels):
    # Assert that the page margins aren't clipped by body's overflow
    assert_pixels('''
        rr______
        rr______
        __BBBB__
        __BBBB__
        __BBBB__
        __BBBB__
        ________
        ________
    ''', '''
      <style>
        @page {
          size: 8px;
          margin: 2px;
          background:#fff;
          @top-left-corner { content: ''; background:#f00; } }
        body { overflow: auto; background:#00f; }
      </style>
      ''')


@assert_no_logs
def test_overflow_5(assert_pixels):
    # Regression test for https://github.com/Kozea/WeasyPrint/issues/2026
    assert_pixels('''
        BBBBBB__
        BBBBBB__
        BBBB____
        BBBB____
        BBBB____
        ________
        ________
        ________
    ''', '''
      <style>
        @font-face { src: url(weasyprint.otf); font-family: weasyprint }
        @page { size: 8px }
        body { font-family: weasyprint; line-height: 1; font-size: 2px }
        p { color: blue }
      </style>
      <p>abc</p>
      <p style="height: 3px; overflow: hidden">ab<br>ab<br>ab<br>ab</p>
      ''')


@assert_no_logs
@pytest.mark.parametrize('number, css, pixels', (
    (1, '5px, 5px, 9px, auto', '''
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
        ______rBBBrBg_
        ______BBBBBBg_
        ______BBBBBBg_
        ______BBBBBBg_
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
    '''),
    (2, '5px, 5px, auto, 10px', '''
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
        ______rBBBr___
        ______BBBBB___
        ______BBBBB___
        ______BBBBB___
        ______rBBBr___
        ______BBBBB___
        ______ggggg___
        ______________
        ______________
        ______________
    '''),
    (3, '5px, auto, 9px, 10px', '''
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
        _grBBBrBBBr___
        _gBBBBBBBBB___
        _gBBBBBBBBB___
        _gBBBBBBBBB___
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
    '''),
    (4, 'auto, 5px, 9px, 10px', '''
        ______________
        ______ggggg___
        ______rBBBr___
        ______BBBBB___
        ______BBBBB___
        ______BBBBB___
        ______rBBBr___
        ______BBBBB___
        ______BBBBB___
        ______BBBBB___
        ______________
        ______________
        ______________
        ______________
        ______________
        ______________
    '''),
))
def test_clip(assert_pixels, number, css, pixels):
    assert_pixels(pixels, '''
      <style>
        @page { size: 14px 16px }
        div { margin: 1px; border: 1px green solid;
              background: url(pattern.png);
              position: absolute; /* clip only applies on abspos */
              top: 0; bottom: 2px; left: 0; right: 0;
              clip: rect(%s); }
      </style>
      <div>''' % css)