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
|
#!/usr/bin/env python
import unittest, sys
sys.path.append('..') # this line allows to import the extension code
from simplestyle import parseColor, parseStyle
class ParseColorTest(unittest.TestCase):
"""Test for single transformations"""
def test_namedcolor(self):
"Parse 'red'"
col = parseColor('red')
self.failUnlessEqual((255,0,0),col)
def test_hexcolor4digit(self):
"Parse '#ff0102'"
col = parseColor('#ff0102')
self.failUnlessEqual((255,1,2),col)
def test_hexcolor3digit(self):
"Parse '#fff'"
col = parseColor('#fff')
self.failUnlessEqual((255,255,255),col)
def test_rgbcolorint(self):
"Parse 'rgb(255,255,255)'"
col = parseColor('rgb(255,255,255)')
self.failUnlessEqual((255,255,255),col)
def test_rgbcolorpercent(self):
"Parse 'rgb(100%,100%,100%)'"
col = parseColor('rgb(100%,100%,100%)')
self.failUnlessEqual((255,255,255),col)
def test_rgbcolorpercent2(self):
"Parse 'rgb(100%,100%,100%)'"
col = parseColor('rgb(50%,0%,1%)')
self.failUnlessEqual((127,0,2),col)
def test_rgbcolorpercentdecimal(self):
"Parse 'rgb(66.667%,0%,6.667%)'"
col = parseColor('rgb(66.667%,0%,6.667%)')
self.failUnlessEqual((170, 0, 17),col)
def test_currentColor(self):
"Parse 'currentColor'"
col = parseColor('currentColor')
self.failUnlessEqual(('currentColor'),col)
def test_spaceinstyle(self):
"Parse 'stop-color: rgb(0,0,0)'"
col = parseStyle('stop-color: rgb(0,0,0)')
self.failUnlessEqual({'stop-color': 'rgb(0,0,0)'},col)
#def test_unknowncolor(self):
# "Parse 'unknown'"
# col = parseColor('unknown')
# self.failUnlessEqual((0,0,0),col)
#
if __name__ == '__main__':
unittest.main()
|