File: test_xlink.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 (73 lines) | stat: -rw-r--r-- 2,080 bytes parent folder | download
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
#!/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
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(r'^<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()