Skip to content

Commit

Permalink
Increase test coverage for svg.py (#620)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Cimon <925560+Lucas-C@users.noreply.github.com>
  • Loading branch information
yiweelan and Lucas-C committed Dec 14, 2022
1 parent 2d22963 commit 00f9b2a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/svg/test_transform_viewport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import fpdf
import pytest


def test_rect_transform_width_exception():
svg_data = """<?xml version="1.0" standalone="no"?>
<svg width="10%" height="10cm" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1">
</svg>
"""

svg = fpdf.svg.SVGObject(svg_data)
with pytest.raises(ValueError) as error:
svg.transform_to_rect_viewport(scale=1, width=None, height=10)
assert 'SVG "width" is a percentage, hence a viewport width is required' == str(
error.value
)


def test_rect_transform_height_exception():
svg_data = """<?xml version="1.0" standalone="no"?>
<svg width="10cm" height="10%" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg" version="1.1">
</svg>
"""

svg = fpdf.svg.SVGObject(svg_data)
with pytest.raises(ValueError) as error:
svg.transform_to_rect_viewport(scale=1, width=10, height=None)
assert 'SVG "height" is a percentage, hence a viewport height is required' == str(
error.value
)


def test_rect_transform_vw_zero():
svg_data = """<?xml version="1.0" standalone="no"?>
<svg width="10cm" height="10cm" viewBox="0 0 0 1000" xmlns="http://www.w3.org/2000/svg" version="1.1">
</svg>
"""

svg = fpdf.svg.SVGObject(svg_data)
width, height, context = svg.transform_to_rect_viewport(scale=2, width=10, height=5)
assert width == 0
assert height == 0
assert context is not None

0 comments on commit 00f9b2a

Please sign in to comment.