File: test_presentation.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 (82 lines) | stat: -rw-r--r-- 3,336 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman --<mozman@gmx.at>
# Purpose: test presentation mixin
# Created: 24.10.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License

import unittest

from svgwrite.base import BaseElement
from svgwrite.mixins import Presentation
from svgwrite import rgb

class PresentationClass(BaseElement, Presentation):
    elementname = "line" # element with valid presentation attributes

class MockPaintServer:
    def get_paint_server(self):
        return "url(#mockpaintserver)"

class TestPresentationMixin(unittest.TestCase):
    def test_fill(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.fill(color='red', rule="evenodd", opacity=1.0)
        self.assertEqual(obj.tostring(),
                         '<line fill="red" fill-opacity="1.0" fill-rule="evenodd" />')

    def test_fill_rgb_values(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.fill(color=rgb(10, 20, 30), rule="evenodd", opacity=1.0)
        self.assertEqual(obj.tostring(),
                         '<line fill="rgb(10,20,30)" fill-opacity="1.0" fill-rule="evenodd" />')

    def test_fill_rgb_percentage(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.fill(color=rgb(10, 20, 30, '%'), rule="evenodd", opacity=1.0)
        self.assertEqual(obj.tostring(),
                         '<line fill="rgb(10%,20%,30%)" fill-opacity="1.0" fill-rule="evenodd" />')

    def test_fill_paintserver(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.fill(color=MockPaintServer())
        self.assertEqual(obj.tostring(),
                         '<line fill="url(#mockpaintserver)" />')

    def test_stroke(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.stroke(color='red', width=2, opacity=0.5, linecap='round',
                   linejoin='round', miterlimit='1.5')
        self.assertEqual(obj.tostring(),
                         '<line stroke="red" ' \
                         'stroke-linecap="round" ' \
                         'stroke-linejoin="round" ' \
                         'stroke-miterlimit="1.5" ' \
                         'stroke-opacity="0.5" ' \
                         'stroke-width="2" />')

    def test_stroke_paintserver(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.stroke(color=MockPaintServer())
        self.assertEqual(obj.tostring(),
                         '<line stroke="url(#mockpaintserver)" />')

    def test_dasharray(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.dasharray([1., 0.5], offset=0.5)
        self.assertEqual(obj.tostring(),
                         '<line stroke-dasharray="1.0 0.5" stroke-dashoffset="0.5" />')

        obj.dasharray('1.0 0.5', offset=0.5)
        self.assertEqual(obj.tostring(),
                         '<line stroke-dasharray="1.0 0.5" stroke-dashoffset="0.5" />')

    def test_combi_call(self):
        obj = PresentationClass(debug=True, profile='full')
        obj.fill('red').stroke('blue')
        self.assertEqual(obj.tostring(),
                         '<line fill="red" stroke="blue" />')

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