File: test_opacity.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 (60 lines) | stat: -rw-r--r-- 1,869 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
"""Test opacity."""

from ..testing_utils import assert_no_logs

opacity_source = '''
    <style>
        @page { size: 60px 60px }
        div { background: #000; width: 20px; height: 20px }
    </style>
    %s'''


@assert_no_logs
def test_opacity_zero(assert_same_renderings):
    assert_same_renderings(
        opacity_source % '<div></div>',
        opacity_source % '<div></div><div style="opacity: 0"></div>',
        opacity_source % '<div></div><div style="opacity: 0%"></div>',
    )


@assert_no_logs
def test_opacity_normal_range(assert_same_renderings):
    assert_same_renderings(
        opacity_source % '<div style="background: rgb(102, 102, 102)"></div>',
        opacity_source % '<div style="opacity: 0.6"></div>',
        opacity_source % '<div style="opacity: 60%"></div>',
        opacity_source % '<div style="opacity: 60.0%"></div>',
    )


@assert_no_logs
def test_opacity_nested(assert_same_renderings):
    assert_same_renderings(
        opacity_source % '<div style="background: rgb(102, 102, 102)"></div>',
        opacity_source % '<div style="opacity: 0.6"></div>',
        opacity_source % '''
          <div style="background: none; opacity: 0.666666">
            <div style="opacity: 0.9"></div>
          </div>
        ''',  # 0.9 * 0.666666 == 0.6
    )


@assert_no_logs
def test_opacity_percent_clamp_down(assert_same_renderings):
    assert_same_renderings(
        opacity_source % '<div></div>',
        opacity_source % '<div style="opacity: 1.2"></div>',
        opacity_source % '<div style="opacity: 120%"></div>',
    )


@assert_no_logs
def test_opacity_percent_clamp_up(assert_same_renderings):
    assert_same_renderings(
        opacity_source % '<div></div>',
        opacity_source % '<div></div><div style="opacity: -0.2"></div>',
        opacity_source % '<div></div><div style="opacity: -20%"></div>',
    )