mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-09-11 20:47:56 +03:00
Improve coverage
This commit is contained in:
parent
0010778e10
commit
7d2913ccad
@ -521,3 +521,34 @@ def test_linear_gradient_opacity(assert_pixels):
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(#grad)" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
@pytest.mark.parametrize('url', ('#grad\'', '\'#gra', '!', '#'))
|
||||
def test_gradient_bad_url(assert_pixels, url):
|
||||
assert_pixels('''
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
__________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 10px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="10px" height="10px" xmlns="https://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient id="grad" x1="0" y1="0" x2="0" y2="1"
|
||||
gradientUnits="objectBoundingBox">
|
||||
<stop stop-color="blue"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect x="0" y="0" width="10" height="10" fill="url(%s)" />
|
||||
</svg>
|
||||
''' % url)
|
||||
|
@ -387,3 +387,27 @@ def test_transform_multiple(assert_pixels):
|
||||
stroke-width="2" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_transform_unknown(assert_pixels):
|
||||
assert_pixels('''
|
||||
RRRRR____
|
||||
R__RR____
|
||||
R__RR____
|
||||
R__RR____
|
||||
RRRRR____
|
||||
RRRRR____
|
||||
_________
|
||||
_________
|
||||
_________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 9px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="9px" height="9px" xmlns="https://www.w3.org/2000/svg">
|
||||
<rect x="0" y="0" width="4" height="5" transform="unknown(2)"
|
||||
stroke-width="2" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
||||
|
101
tests/draw/svg/test_units.py
Normal file
101
tests/draw/svg/test_units.py
Normal file
@ -0,0 +1,101 @@
|
||||
"""Test SVG units."""
|
||||
|
||||
from ...testing_utils import assert_no_logs
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_units_px(assert_pixels):
|
||||
assert_pixels('''
|
||||
_________
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 9px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="9px" height="9px" xmlns="https://www.w3.org/2000/svg">
|
||||
<rect x="2px" y="2px" width="5px" height="5px"
|
||||
stroke-width="2px" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_units_em(assert_pixels):
|
||||
assert_pixels('''
|
||||
_________
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 9px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="9px" height="9px" font-size="1px"
|
||||
xmlns="https://www.w3.org/2000/svg">
|
||||
<rect x="2em" y="2em" width="5em" height="5em"
|
||||
stroke-width="2em" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_units_ex(assert_pixels):
|
||||
assert_pixels('''
|
||||
_________
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 9px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="9px" height="9px" font-size="1px"
|
||||
xmlns="https://www.w3.org/2000/svg">
|
||||
<rect x="4ex" y="4ex" width="10ex" height="10ex"
|
||||
stroke-width="4ex" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
def test_units_unknown(assert_pixels):
|
||||
assert_pixels('''
|
||||
_RRRRRRR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RR___RR_
|
||||
_RRRRRRR_
|
||||
_RRRRRRR_
|
||||
_________
|
||||
_________
|
||||
_________
|
||||
''', '''
|
||||
<style>
|
||||
@page { size: 9px }
|
||||
svg { display: block }
|
||||
</style>
|
||||
<svg width="9px" height="9px" xmlns="https://www.w3.org/2000/svg">
|
||||
<rect x="2px" y="2unk" width="5px" height="5px"
|
||||
stroke-width="2px" stroke="red" fill="none" />
|
||||
</svg>
|
||||
''')
|
@ -124,8 +124,8 @@ def parse_url(url):
|
||||
if url and url.startswith('url(') and url.endswith(')'):
|
||||
url = url[4:-1]
|
||||
if len(url) >= 2:
|
||||
for quote in '\'"':
|
||||
if url[0] == url[-1]:
|
||||
for quote in ("'", '"'):
|
||||
if url[0] == url[-1] == quote:
|
||||
url = url[1:-1]
|
||||
break
|
||||
return urlparse(url or '')
|
||||
|
Loading…
Reference in New Issue
Block a user