File: test_viewbox.py

package info (click to toggle)
svgwrite 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 2,092 kB
  • sloc: python: 12,603; makefile: 117; sh: 5
file content (59 lines) | stat: -rw-r--r-- 1,917 bytes parent folder | download | duplicates (3)
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
#!/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: MIT License

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()