Skip to content

Commit

Permalink
Merge pull request #62 from hartwork/issue-61-get-width-height-viewbo…
Browse files Browse the repository at this point in the history
…x-back-into-svg-output

Get width, height and viewBox back into SVG output (fixes #61)
  • Loading branch information
btel authored Feb 10, 2021
2 parents 4b77203 + 0c1d861 commit 10a0820
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (C) 2021 Sebastian Pipping <[email protected]>
# Licensed under the MIT License

name: Run the test suite

on:
- pull_request
- push

jobs:
run-tests:
name: Run the test suite
strategy:
matrix:
python-version: [2.7, 3.5, 3.9] # no explicit need for 3.6, 3.7, 3.8
runs-on: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Run the test suite
run: |
python --version
pip install nose
pip install -e .
python -m nose -v
6 changes: 3 additions & 3 deletions src/svgutils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ def __init__(self, width=None, height=None):

if width:
try:
# width is an instance of Unit
self._width = width.value
self.width = width # this goes to @width.setter a few lines down
except AttributeError:
# int or str
self._width = width

if height:
try:
self._height = height.value
self.height = height # this goes to @height.setter a few lines down
except AttributeError:
self._height = height

Expand Down
14 changes: 14 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# coding=utf-8
from tempfile import NamedTemporaryFile

from svgutils import transform
from svgutils.compose import Unit
Expand Down Expand Up @@ -61,3 +62,16 @@ def test_create_svg_figure():

svg_fig = transform.SVGFigure("2", "3")
assert "svg" in svg_fig.to_str().decode("ascii")


def test_svg_figure_writes_width_height_and_view_box():
svg_fig = transform.SVGFigure(Unit("400mm"), Unit("300mm"))

with NamedTemporaryFile() as f1:
svg_fig.save(f1.name)
with open(f1.name) as f2:
written_content = f2.read()

assert 'width="400.0mm"' in written_content
assert 'height="300.0mm"' in written_content
assert 'viewBox="0 0 400.0 300.0"' in written_content

0 comments on commit 10a0820

Please sign in to comment.