1. Manfred Moitzi
  2. svgwrite

Commits

Manfred Moitzi  committed f136ae7

updated doc (interfaces -> mixins)

  • Participants
  • Parent commits 40abbb6
  • Branches default

Comments (0)

Files changed (26)

File doc/classes/animate.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 
 Methods
 -------
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.animate.Set`
 
 Methods
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.animate.Set`
 
 Methods
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.animate.Animate`
 
 SVG Animation Attributes
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.animate.Animate`
 
 Methods

File doc/classes/defs.rst

View file
 
 * :class:`svgwrite.base.BaseElement`
 * :class:`svgwrite.container.Group`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 Standard SVG Attributes
 -----------------------

File doc/classes/drawing.rst

View file
 * :class:`svgwrite.base.BaseElement`
 * :class:`svgwrite.container.Symbol`
 * :class:`svgwrite.container.SVG`
-* :class:`svgwrite.interface.ITransform`
-* :class:`svgwrite.interface.IViewBox`
+* :class:`svgwrite.mixins.Transform`
+* :class:`svgwrite.mixins.ViewBox`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Clipping`
 * :class:`svgwrite.elementfactory.ElementFactory`

File doc/classes/filters.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.mixins.Presentation`
 
 Methods

File doc/classes/gradients.rst

View file
 
 * **gradientTransform** -- `<transform-list>`
 
-  Use the :class:`-svgwrite.interface.ITransform` interface to set transformations.
+  Use the :class:`-svgwrite.mixins.Transform` interface to set transformations.
 
   Contains the definition of an optional additional transformation from the
   gradient coordinate system onto the target coordinate system (i.e.,
 
 * **gradientTransform** -- `<transform-list>`
 
-  Use the :class:`-svgwrite.interface.ITransform` interface to set transformations.
+  Use the :class:`-svgwrite.mixins.Transform` interface to set transformations.
 
   See :class:`LinearGradient`
 

File doc/classes/group.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 Standard SVG Attributes
 -----------------------

File doc/classes/hyperlink.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 * **xlink:href** -- `string`
 

File doc/classes/image.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Clipping`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 * **x** -- `<coordinate>`
 

File doc/classes/interface.rst

View file
-IViewBox interface
-==================
+ViewBox Mixin
+=============
 
-.. autoclass:: svgwrite.interface.IViewBox
+.. autoclass:: svgwrite.mixins.ViewBox
 
 Methods
 -------
 
-.. automethod:: svgwrite.interface.IViewBox.viewbox
+.. automethod:: svgwrite.mixins.ViewBox.viewbox
 
-.. automethod:: svgwrite.interface.IViewBox.stretch
+.. automethod:: svgwrite.mixins.ViewBox.stretch
 
-.. automethod:: svgwrite.interface.IViewBox.fit
+.. automethod:: svgwrite.mixins.ViewBox.fit
 
-ITransform interface
-====================
+Transform Mixin
+===============
 
-.. autoclass:: svgwrite.interface.ITransform
+.. autoclass:: svgwrite.mixins.Transform
 
 Methods
 -------
 
-.. automethod:: svgwrite.interface.ITransform.translate
+.. automethod:: svgwrite.mixins.Transform.translate
 
-.. automethod:: svgwrite.interface.ITransform.rotate
+.. automethod:: svgwrite.mixins.Transform.rotate
 
-.. automethod:: svgwrite.interface.ITransform.skewX
+.. automethod:: svgwrite.mixins.Transform.skewX
 
-.. automethod:: svgwrite.interface.ITransform.skewY
+.. automethod:: svgwrite.mixins.Transform.skewY
 
-.. automethod:: svgwrite.interface.ITransform.scale
+.. automethod:: svgwrite.mixins.Transform.scale
 
-IXLink interface
-================
+XLink Mixin
+===========
 
-.. autoclass:: svgwrite.interface.IXLink
+.. autoclass:: svgwrite.mixins.XLink
 
 Methods
 -------
 
-.. automethod:: svgwrite.interface.IXLink.set_href
+.. automethod:: svgwrite.mixins.XLink.set_href
 
-.. automethod:: svgwrite.interface.IXLink.set_xlink
+.. automethod:: svgwrite.mixins.XLink.set_xlink
 
 Set **xlink:actuate** and **xlink:type** by the index operator::
 

File doc/classes/marker.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IViewBox`
+* :class:`svgwrite.mixins.ViewBox`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **viewBox** -- use :class:`svgwrite.interface.IViewBox` interface
+* **viewBox** -- use :class:`svgwrite.mixins.ViewBox` interface
 
-* **preserveAspectRatio** -- use :class:`svgwrite.interface.IViewBox`
+* **preserveAspectRatio** -- use :class:`svgwrite.mixins.ViewBox`
   interface
 
 * **markerUnits** -- ``'strokeWidth|userSpaceOnUse'``

File doc/classes/masking.rst

View file
   *False*: if document rendering can proceed
   even if external resources are unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` methods
+* **transform** -- use :class:`svgwrite.mixins.Transform` methods
 
 * **clipPathUnits** -- ``'userSpaceOnUse | objectBoundingBox'``
 

File doc/classes/path.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Markers`
 
   *False*: if document rendering can proceed
   even if external resources are unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` methods
+* **transform** -- use :class:`svgwrite.mixins.Transform` methods
 
 * **pathLength** -- `<number>`
 

File doc/classes/pattern.rst

View file
 
 * **patternTransform** -- `<transform-list>`
 
-  Use the :class:`~svgwrite.interface.ITransform` interface to set transformations.
+  Use the :class:`~svgwrite.mixins.Transform` interface to set transformations.
 
   Contains the definition of an optional additional transformation from the
   pattern coordinate system onto the target coordinate system (i.e.,
 
 * **preserveAspectRatio** -- ``'[defer] <align> [<meetOrSlice>]'``
 
-  Use the :class:`~svgwrite.interface.IViewBox` interface to set **viewbox**
+  Use the :class:`~svgwrite.mixins.ViewBox` interface to set **viewbox**
   and **preserveAspectRatio**.

File doc/classes/shapes.rst

View file
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 Common Standard SVG Attributes
 ------------------------------
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Markers`
 
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 Circle
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 Ellipse
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 Polyline
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Markers`
 
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Markers`

File doc/classes/svg.rst

View file
 * :class:`svgwrite.base.BaseElement`
 * :class:`svgwrite.container.Symbol`
 * :class:`svgwrite.container.SVG`
-* :class:`svgwrite.interface.ITransform`
-* :class:`svgwrite.interface.IViewBox`
+* :class:`svgwrite.mixins.Transform`
+* :class:`svgwrite.mixins.ViewBox`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **transform** -- use :class:`svgwrite.interface.ITransform` interface
+* **transform** -- use :class:`svgwrite.mixins.Transform` interface
 
 * **x** -- `<coordinate>`
 
 
   Default is ``'100%'``.
 
-* **viewBox** -- :class:`svgwrite.interface.IViewBox` interface
+* **viewBox** -- :class:`svgwrite.mixins.ViewBox` interface
 
-* **preserveAspectRatio**  -- :class:`svgwrite.interface.IViewBox` interface
+* **preserveAspectRatio**  -- :class:`svgwrite.mixins.ViewBox` interface
 
 * **zoomAndPan** -- ``'disable | magnify'``
 

File doc/classes/symbol.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IViewBox`
+* :class:`svgwrite.mixins.ViewBox`
 * :class:`svgwrite.mixins.Presentation`
 * :class:`svgwrite.mixins.Clipping`
 
   *False*: if document rendering can proceed even if external resources are
   unavailable else: *True*
 
-* **viewBox** -- use :class:`svgwrite.interface.IViewBox` interface
+* **viewBox** -- use :class:`svgwrite.mixins.ViewBox` interface
 
-* **preserveAspectRatio** -- use :class:`svgwrite.interface.IViewBox`
+* **preserveAspectRatio** -- use :class:`svgwrite.mixins.ViewBox`
   interface
 
 Standard SVG Attributes

File doc/classes/text.rst

View file
 
 * :class:`svgwrite.base.BaseElement`
 * :class:`svgwrite.base.TSpan`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 TSpan
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
+* :class:`svgwrite.mixins.Transform`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes

File doc/classes/use.rst

View file
 --------------
 
 * :class:`svgwrite.base.BaseElement`
-* :class:`svgwrite.interface.ITransform`
-* :class:`svgwrite.interface.IXLink`
+* :class:`svgwrite.mixins.Transform`
+* :class:`svgwrite.mixins.XLink`
 * :class:`svgwrite.mixins.Presentation`
 
 SVG Attributes
 
   Default is ``'100%'``.
 
-* **transform** -- :class:`svgwrite.interface.ITransform` interface
+* **transform** -- :class:`svgwrite.mixins.Transform` interface
 
 * **xlink:href** -- `string`
 

File doc/index.rst

View file
    classes/fe_tile
    classes/fe_turbulence
 
-Interfaces
-----------
-
-.. toctree::
-   :maxdepth: 1
-
-   classes/interface
-
 Mixins
 ------
 
 .. toctree::
    :maxdepth: 1
 
+   classes/interface
    classes/mixins
 
 Indices and tables

File doc/overview.rst

View file
 Interfaces and Mixins
 ---------------------
 
-:class:`~svgwrite.interface.IViewBox`, :class:`~svgwrite.interface.ITransform`,
-:class:`~svgwrite.interface.IXLink`,
+:class:`~svgwrite.mixins.ViewBox`, :class:`~svgwrite.mixins.Transform`,
+:class:`~svgwrite.mixins.XLink`,
 :class:`~svgwrite.mixins.Presentation`, :class:`~svgwrite.mixins.MediaGroup`,
 :class:`~svgwrite.mixins.Markers`, :class:`~svgwrite.mixins.Clipping`,
 

File tests/test_itransform.py

-#!/usr/bin/env python
-#coding:utf-8
-# Author:  mozman --<mozman@gmx.at>
-# Purpose: test ITransform interface
-# Created: 25.09.2010
-# Copyright (C) 2010, Manfred Moitzi
-# License: GPLv3
-
-import sys
-import unittest
-
-from svgwrite.params import Parameter
-from svgwrite.base import BaseElement
-from svgwrite.mixins import Transform
-
-class Mock(BaseElement, Transform):
-    elementname = 'g'
-    _parameter = Parameter(True, 'full')
-
-class TestITransfer(unittest.TestCase):
-    def test_mock_class(self):
-        m = Mock()
-        self.assertEqual(m.tostring(), '<g />')
-
-    def test_translate_tx(self):
-        m = Mock()
-        m.translate(tx=10)
-        self.assertEqual(m.tostring(), '<g transform="translate(10)" />')
-
-    def test_translate_tx_ty(self):
-        m = Mock()
-        # strings allowed
-        m.translate(tx='10', ty=20)
-        self.assertEqual(m.tostring(), '<g transform="translate(10,20)" />')
-
-    def test_translate_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.translate, '10cm')
-
-    def test_rotate(self):
-        m = Mock()
-        m.rotate(angle=30)
-        self.assertEqual(m.tostring(), '<g transform="rotate(30)" />')
-
-    def test_rotate_center(self):
-        m = Mock()
-        # strings allowed
-        m.rotate(angle='30', center=(1,2))
-        self.assertEqual(m.tostring(), '<g transform="rotate(30,1,2)" />')
-
-    def test_rotate_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.rotate, '30deg')
-        self.assertRaises(TypeError, m.rotate, '30', center=('1cm', '1cm'))
-
-    def test_scale_sx(self):
-        m = Mock()
-        m.scale(sx=3)
-        self.assertEqual(m.tostring(), '<g transform="scale(3)" />')
-
-    def test_scale_sx_sy(self):
-        m = Mock()
-        m.scale(sx='3', sy=2)
-        self.assertEqual(m.tostring(), '<g transform="scale(3,2)" />')
-
-    def test_scale_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.scale, '3cm')
-        self.assertRaises(TypeError, m.scale, '3', '2cm')
-
-    def test_skewX(self):
-        m = Mock()
-        m.skewX(angle=30)
-        self.assertEqual(m.tostring(), '<g transform="skewX(30)" />')
-
-    def test_skewX_str(self):
-        m = Mock()
-        m.skewX(angle='30')
-        self.assertEqual(m.tostring(), '<g transform="skewX(30)" />')
-
-    def test_skewX_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.skewX, '3deg')
-
-    def test_skewY(self):
-        m = Mock()
-        m.skewY(angle=30)
-        self.assertEqual(m.tostring(), '<g transform="skewY(30)" />')
-
-    def test_skewY_str(self):
-        m = Mock()
-        m.skewY(angle='30')
-        self.assertEqual(m.tostring(), '<g transform="skewY(30)" />')
-
-    def test_skewY_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.skewY, '3deg')
-
-    def test_matrix(self):
-        m = Mock()
-        m.matrix(1,2,3,4,5,6)
-        self.assertEqual(m.tostring(), '<g transform="matrix(1,2,3,4,5,6)" />')
-
-    def test_matrix_too_few_params(self):
-        m = Mock()
-        self.assertRaises(TypeError, m.matrix, 1, 2, 3, 4, 5)
-
-    def test_combine_tranformation(self):
-        m = Mock()
-        m.translate(10,20)
-        m.scale(2,2)
-        self.assertEqual(m.tostring(), '<g transform="translate(10,20) scale(2,2)" />')
-
-if __name__=='__main__':
-    unittest.main()

File tests/test_iviewbox.py

-#!/usr/bin/env python
-#coding:utf-8
-# Author:  mozman --<mozman@gmx.at>
-# Purpose: test ITransform interface
-# Created: 25.09.2010
-# Copyright (C) 2010, Manfred Moitzi
-# License: GPLv3
-
-import sys
-import unittest
-
-from svgwrite.params import Parameter
-from svgwrite.base import BaseElement
-from svgwrite.mixins import ViewBox
-
-class Mock(BaseElement, ViewBox):
-    elementname = 'svg'
-    _parameter = Parameter(True, 'full')
-
-class TestViewBox(unittest.TestCase):
-    def test_mock_class(self):
-        m = Mock()
-        self.assertEqual(m.tostring(), '<svg />')
-
-    def test_viewbox(self):
-        m = Mock()
-        m.viewbox(minx=1, miny=2, width=10, height=20)
-        self.assertEqual(m.tostring(), '<svg viewBox="1,2,10,20" />')
-
-    def test_viewbox_err(self):
-        m = Mock()
-        # no units allowed
-        self.assertRaises(TypeError, m.viewbox, '10cm')
-
-    def test_strech(self):
-        m = Mock()
-        m.stretch()
-        self.assertEqual(m.tostring(), '<svg preserveAspectRatio="none" />')
-
-    def test_fit_horiz(self):
-        m = Mock()
-        for align, expected in [('left', 'xMin'), ('center', 'xMid'), ('right', 'xMax')]:
-            m.fit(align, 'top', 'meet')
-            self.assertEqual(m.tostring(), '<svg preserveAspectRatio="%sYMin meet" />' % expected)
-
-    def test_fit_vert(self):
-        m = Mock()
-        for align, expected in [('top', 'YMin'), ('middle', 'YMid'), ('bottom', 'YMax')]:
-            m.fit('left', align, 'slice')
-            self.assertEqual(m.tostring(), '<svg preserveAspectRatio="xMin%s slice" />' % expected)
-
-    def test_fit_err(self):
-        m = Mock()
-        self.assertRaises(ValueError, m.fit, scale='invalid')
-        self.assertRaises(KeyError, m.fit, horiz='invalid')
-        self.assertRaises(KeyError, m.fit, vert='invalid')
-
-if __name__=='__main__':
-    unittest.main()

File tests/test_ixlink.py

-#!/usr/bin/env python
-#coding:utf-8
-# Author:  mozman --<mozman@gmx.at>
-# Purpose: test ITransform interface
-# Created: 25.09.2010
-# Copyright (C) 2010, Manfred Moitzi
-# License: GPLv3
-
-import sys
-import unittest
-import re
-
-from svgwrite.container import Group
-from svgwrite.params import Parameter
-from svgwrite.base import BaseElement
-from svgwrite.mixins import XLink
-
-class Mock(BaseElement, XLink):
-    elementname = 'use'
-    _parameter = Parameter(True, 'full')
-
-    def next_id(self):
-        return "id999"
-
-class TestIXLink(unittest.TestCase):
-    def test_mock_class(self):
-        m = Mock()
-        self.assertEqual(m.tostring(), '<use />')
-
-    def test_href(self):
-        m = Mock()
-        m.set_href('#an_id')
-        self.assertEqual(m.tostring(), '<use xlink:href="#an_id" />')
-
-    def test_object_link(self):
-        g = Group(id='test')
-        m = Mock()
-        m.set_href(g)
-        self.assertEqual(m.tostring(), '<use xlink:href="#test" />')
-
-    def test_object_link_auto_id(self):
-        g = Group()
-        m = Mock()
-        m.set_href(g)
-        self.assertTrue(re.match('^<use xlink:href="#id\d+" />$', m.tostring()))
-
-    def test_set_xlink_show(self):
-        m = Mock()
-        m.set_xlink(show='new')
-        self.assertEqual(m.tostring(), '<use xlink:show="new" />')
-        m.set_xlink(show='replace')
-        self.assertEqual(m.tostring(), '<use xlink:show="replace" />')
-
-    def test_set_xlink_role(self):
-        m = Mock()
-        m.set_xlink(role='http://test/role')
-        self.assertEqual(m.tostring(), '<use xlink:role="http://test/role" />')
-
-    def test_set_xlink_arcrole(self):
-        m = Mock()
-        m.set_xlink(arcrole='http://test/arcrole')
-        self.assertEqual(m.tostring(), '<use xlink:arcrole="http://test/arcrole" />')
-
-    def test_set_xlink_title(self):
-        m = Mock()
-        m.set_xlink(title='test')
-        self.assertEqual(m.tostring(), '<use xlink:title="test" />')
-
-if __name__=='__main__':
-    unittest.main()

File tests/test_transform.py

View file
+#!/usr/bin/env python
+#coding:utf-8
+# Author:  mozman --<mozman@gmx.at>
+# Purpose: test ITransform interface
+# Created: 25.09.2010
+# Copyright (C) 2010, Manfred Moitzi
+# License: GPLv3
+
+import sys
+import unittest
+
+from svgwrite.params import Parameter
+from svgwrite.base import BaseElement
+from svgwrite.mixins import Transform
+
+class Mock(BaseElement, Transform):
+    elementname = 'g'
+    _parameter = Parameter(True, 'full')
+
+class TestITransfer(unittest.TestCase):
+    def test_mock_class(self):
+        m = Mock()
+        self.assertEqual(m.tostring(), '<g />')
+
+    def test_translate_tx(self):
+        m = Mock()
+        m.translate(tx=10)
+        self.assertEqual(m.tostring(), '<g transform="translate(10)" />')
+
+    def test_translate_tx_ty(self):
+        m = Mock()
+        # strings allowed
+        m.translate(tx='10', ty=20)
+        self.assertEqual(m.tostring(), '<g transform="translate(10,20)" />')
+
+    def test_translate_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.translate, '10cm')
+
+    def test_rotate(self):
+        m = Mock()
+        m.rotate(angle=30)
+        self.assertEqual(m.tostring(), '<g transform="rotate(30)" />')
+
+    def test_rotate_center(self):
+        m = Mock()
+        # strings allowed
+        m.rotate(angle='30', center=(1,2))
+        self.assertEqual(m.tostring(), '<g transform="rotate(30,1,2)" />')
+
+    def test_rotate_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.rotate, '30deg')
+        self.assertRaises(TypeError, m.rotate, '30', center=('1cm', '1cm'))
+
+    def test_scale_sx(self):
+        m = Mock()
+        m.scale(sx=3)
+        self.assertEqual(m.tostring(), '<g transform="scale(3)" />')
+
+    def test_scale_sx_sy(self):
+        m = Mock()
+        m.scale(sx='3', sy=2)
+        self.assertEqual(m.tostring(), '<g transform="scale(3,2)" />')
+
+    def test_scale_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.scale, '3cm')
+        self.assertRaises(TypeError, m.scale, '3', '2cm')
+
+    def test_skewX(self):
+        m = Mock()
+        m.skewX(angle=30)
+        self.assertEqual(m.tostring(), '<g transform="skewX(30)" />')
+
+    def test_skewX_str(self):
+        m = Mock()
+        m.skewX(angle='30')
+        self.assertEqual(m.tostring(), '<g transform="skewX(30)" />')
+
+    def test_skewX_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.skewX, '3deg')
+
+    def test_skewY(self):
+        m = Mock()
+        m.skewY(angle=30)
+        self.assertEqual(m.tostring(), '<g transform="skewY(30)" />')
+
+    def test_skewY_str(self):
+        m = Mock()
+        m.skewY(angle='30')
+        self.assertEqual(m.tostring(), '<g transform="skewY(30)" />')
+
+    def test_skewY_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.skewY, '3deg')
+
+    def test_matrix(self):
+        m = Mock()
+        m.matrix(1,2,3,4,5,6)
+        self.assertEqual(m.tostring(), '<g transform="matrix(1,2,3,4,5,6)" />')
+
+    def test_matrix_too_few_params(self):
+        m = Mock()
+        self.assertRaises(TypeError, m.matrix, 1, 2, 3, 4, 5)
+
+    def test_combine_tranformation(self):
+        m = Mock()
+        m.translate(10,20)
+        m.scale(2,2)
+        self.assertEqual(m.tostring(), '<g transform="translate(10,20) scale(2,2)" />')
+
+if __name__=='__main__':
+    unittest.main()

File tests/test_viewbox.py

View file
+#!/usr/bin/env python
+#coding:utf-8
+# Author:  mozman --<mozman@gmx.at>
+# Purpose: test ITransform interface
+# Created: 25.09.2010
+# Copyright (C) 2010, Manfred Moitzi
+# License: GPLv3
+
+import sys
+import unittest
+
+from svgwrite.params import Parameter
+from svgwrite.base import BaseElement
+from svgwrite.mixins import ViewBox
+
+class Mock(BaseElement, ViewBox):
+    elementname = 'svg'
+    _parameter = Parameter(True, 'full')
+
+class TestViewBox(unittest.TestCase):
+    def test_mock_class(self):
+        m = Mock()
+        self.assertEqual(m.tostring(), '<svg />')
+
+    def test_viewbox(self):
+        m = Mock()
+        m.viewbox(minx=1, miny=2, width=10, height=20)
+        self.assertEqual(m.tostring(), '<svg viewBox="1,2,10,20" />')
+
+    def test_viewbox_err(self):
+        m = Mock()
+        # no units allowed
+        self.assertRaises(TypeError, m.viewbox, '10cm')
+
+    def test_strech(self):
+        m = Mock()
+        m.stretch()
+        self.assertEqual(m.tostring(), '<svg preserveAspectRatio="none" />')
+
+    def test_fit_horiz(self):
+        m = Mock()
+        for align, expected in [('left', 'xMin'), ('center', 'xMid'), ('right', 'xMax')]:
+            m.fit(align, 'top', 'meet')
+            self.assertEqual(m.tostring(), '<svg preserveAspectRatio="%sYMin meet" />' % expected)
+
+    def test_fit_vert(self):
+        m = Mock()
+        for align, expected in [('top', 'YMin'), ('middle', 'YMid'), ('bottom', 'YMax')]:
+            m.fit('left', align, 'slice')
+            self.assertEqual(m.tostring(), '<svg preserveAspectRatio="xMin%s slice" />' % expected)
+
+    def test_fit_err(self):
+        m = Mock()
+        self.assertRaises(ValueError, m.fit, scale='invalid')
+        self.assertRaises(KeyError, m.fit, horiz='invalid')
+        self.assertRaises(KeyError, m.fit, vert='invalid')
+
+if __name__=='__main__':
+    unittest.main()

File tests/test_xlink.py

View file
+#!/usr/bin/env python
+#coding:utf-8
+# Author:  mozman --<mozman@gmx.at>
+# Purpose: test ITransform interface
+# Created: 25.09.2010
+# Copyright (C) 2010, Manfred Moitzi
+# License: GPLv3
+
+import sys
+import unittest
+import re
+
+from svgwrite.container import Group
+from svgwrite.params import Parameter
+from svgwrite.base import BaseElement
+from svgwrite.mixins import XLink
+
+class Mock(BaseElement, XLink):
+    elementname = 'use'
+    _parameter = Parameter(True, 'full')
+
+    def next_id(self):
+        return "id999"
+
+class TestIXLink(unittest.TestCase):
+    def test_mock_class(self):
+        m = Mock()
+        self.assertEqual(m.tostring(), '<use />')
+
+    def test_href(self):
+        m = Mock()
+        m.set_href('#an_id')
+        self.assertEqual(m.tostring(), '<use xlink:href="#an_id" />')
+
+    def test_object_link(self):
+        g = Group(id='test')
+        m = Mock()
+        m.set_href(g)
+        self.assertEqual(m.tostring(), '<use xlink:href="#test" />')
+
+    def test_object_link_auto_id(self):
+        g = Group()
+        m = Mock()
+        m.set_href(g)
+        self.assertTrue(re.match('^<use xlink:href="#id\d+" />$', m.tostring()))
+
+    def test_set_xlink_show(self):
+        m = Mock()
+        m.set_xlink(show='new')
+        self.assertEqual(m.tostring(), '<use xlink:show="new" />')
+        m.set_xlink(show='replace')
+        self.assertEqual(m.tostring(), '<use xlink:show="replace" />')
+
+    def test_set_xlink_role(self):
+        m = Mock()
+        m.set_xlink(role='http://test/role')
+        self.assertEqual(m.tostring(), '<use xlink:role="http://test/role" />')
+
+    def test_set_xlink_arcrole(self):
+        m = Mock()
+        m.set_xlink(arcrole='http://test/arcrole')
+        self.assertEqual(m.tostring(), '<use xlink:arcrole="http://test/arcrole" />')
+
+    def test_set_xlink_title(self):
+        m = Mock()
+        m.set_xlink(title='test')
+        self.assertEqual(m.tostring(), '<use xlink:title="test" />')
+
+if __name__=='__main__':
+    unittest.main()