File: test_document.py

package info (click to toggle)
python-enable 3.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 10,392 kB
  • ctags: 17,135
  • sloc: cpp: 79,151; python: 29,601; makefile: 2,926; sh: 43
file content (78 lines) | stat: -rw-r--r-- 2,656 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
74
75
76
77
78
import unittest
import enthought.savage.svg.document as document
import xml.etree.cElementTree as etree
from cStringIO import StringIO

from enthought.savage.svg.backends.kiva.renderer import Renderer as KivaRenderer

minimalSVG = etree.parse(StringIO(r"""<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"></svg>"""))

class TestBrushFromColourValue(unittest.TestCase):

    def setUp(self):
        self.document = document.SVGDocument(minimalSVG.getroot(), renderer=KivaRenderer())
        self.stateStack = [{}]

    def testNone(self):
        self.document.state["fill"] = 'none'
        self.assertEqual(
            self.document.getBrushFromState(),
            None
        )

    def testCurrentColour(self):
        self.document.state["fill"] = 'currentColor'
        self.document.state["color"] = "rgb(100,100,100)"
        self.assertEqual(
            self.document.getBrushFromState().color,
            (100,100,100,255)
        )

    def testCurrentColourNull(self):
        self.document.state["fill"] = 'currentColor'
        self.assertEqual(
            self.document.getBrushFromState(),
            None
        )

    def testOpacity(self):
        self.document.state["fill"] = 'rgb(255,100,10)'
        self.document.state["fill-opacity"] = 0.5
        self.assertEqual(
            self.document.getBrushFromState().color[-1],
            127.5
        )

    def testOpacityClampHigh(self):
        self.document.state["fill"] = 'rgb(255,100,10)'
        self.document.state["fill-opacity"] = 5
        self.assertEqual(
            self.document.getBrushFromState().color[-1],
            255
        )

    def testOpacityClampLow(self):
        self.document.state["fill"] = 'rgb(255,100,10)'
        self.document.state["fill-opacity"] = -100
        self.assertEqual(
            self.document.getBrushFromState().color[-1],
            0
        )
    def testURLFallback(self):
        self.document.state["fill"] = "url(http://google.com) red"
        self.assertEqual(
            self.document.getBrushFromState().color,
            (255,0,0)
        )

class TestValueToPixels(unittest.TestCase):
    """ Make sure that CSS length values get converted correctly to pixels"""
    def testDefault(self):
        got = document.valueToPixels("12")
        self.assertEqual(got, 12)
    def testPointConversion(self):
        got = document.valueToPixels('14pt')
        self.assertEqual(got, 22)