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 83 84 85 86 87 88 89 90 91 92 93 94 95
|
import unittest
import enable.savage.svg.document as document
import xml.etree.cElementTree as etree
from cStringIO import StringIO
from enable.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, 255)
)
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, 14)
def testInchConversion(self):
got = document.valueToPixels('2in')
self.assertEqual(got, 144)
def testCentimeterConversion(self):
got = document.valueToPixels('2cm')
self.assertAlmostEqual(got, 56.7, places=1)
def testMillimeterConversion(self):
got = document.valueToPixels('2mm')
self.assertAlmostEqual(got, 5.67, places=2)
|