File: test_svgattributes.py

package info (click to toggle)
svgwrite 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,304 kB
  • sloc: python: 12,524; makefile: 116; sh: 5
file content (77 lines) | stat: -rw-r--r-- 3,066 bytes parent folder | download | duplicates (4)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: test SVGAttribute
# Created: 12.10.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License

import sys
import unittest

from svgwrite.data.types import SVGAttribute, SVGMultiAttribute

class TestSVGMultiAttribute(unittest.TestCase):
    def setUp(self):
        self.ma = SVGMultiAttribute({
            '*': SVGAttribute('x',
                              anim=True,
                              types=frozenset(['coordinate']),
                              const=frozenset(['star'])),
            'text tref tspan': SVGAttribute('x',
                                            anim=False,
                                            types=frozenset(['list-of-coordinate']),
                                            const=frozenset(['text']))
            }
        )

    def test_no_default(self):
        ma = SVGMultiAttribute({
            'a': SVGAttribute('x',
                              anim=True,
                              types=frozenset(['coordinate']),
                              const=frozenset(['star'])),
            'b': SVGAttribute('x',
                              anim=False,
                              types=frozenset(['list-of-coordinate']),
                              const=frozenset(['text']))
            }
        )
        self.assertTrue('coordinate' in ma.get_types('c'))

    def test_get_types(self):
        coordinate = frozenset(['coordinate'])
        list_of_coordinates = frozenset(['list-of-coordinate'])

        self.assertEqual(coordinate, self.ma.get_types('line')) # default attribute
        self.assertEqual(coordinate, self.ma.get_types()) # default attribute
        self.assertEqual(list_of_coordinates, self.ma.get_types('text'))
        self.assertEqual(list_of_coordinates, self.ma.get_types('tref'))
        self.assertEqual(list_of_coordinates, self.ma.get_types('tspan'))

    def test_get_anim(self):
        self.assertTrue(self.ma.get_anim('line')) # default attribute
        self.assertTrue(self.ma.get_anim()) # default attribute
        self.assertFalse(self.ma.get_anim('text'))
        self.assertFalse(self.ma.get_anim('tref'))
        self.assertFalse(self.ma.get_anim('tspan'))

    def test_get_const(self):
        star = frozenset(['star'])
        text = frozenset(['text'])

        self.assertEqual(star, self.ma.get_const('line')) # default attribute
        self.assertEqual(star, self.ma.get_const()) # default attribute
        self.assertEqual(text, self.ma.get_const('text'))
        self.assertEqual(text, self.ma.get_const('tref'))
        self.assertEqual(text, self.ma.get_const('tspan'))

    def test_init_error(self):
        # different attribute names
        ma = { '*' : SVGAttribute('x', True, [], []),
               'text' : SVGAttribute('y', False, [], [])
               }
        self.assertRaises(ValueError, SVGMultiAttribute, ma)

if __name__=='__main__':
    unittest.main()