Package cssutils :: Package tests :: Module test_property
[hide private]
[frames] | no frames]

Source Code for Module cssutils.tests.test_property

  1  """Testcases for cssutils.css.property._Property.""" 
  2  __author__ = '$LastChangedBy: doerwalter $' 
  3  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $' 
  4  __version__ = '0.9.2a2, $LastChangedRevision: 160 $' 
  5   
  6  import xml.dom 
  7   
  8  import basetest 
  9   
 10  import cssutils 
 11   
 12   
13 -class PropertyTestCase(basetest.BaseTestCase):
14
15 - def setUp(self):
16 self.r = cssutils.css.property._Property('top', '1px')
17
18 - def test_init(self):
19 "_Property.__init__()" 20 p = cssutils.css.property._Property('top', '1px') 21 self.assertEqual('top', p.name) 22 self.assertEqual('1px', p.value) 23 self.assertEqual('1px', p.cssValue.cssText) 24 self.assertEqual(u'', p.priority) 25 26 self.assertEqual([u'top'], p.seqs[0]) 27 self.assertEqual(type(cssutils.css.CSSValue()), type(p.seqs[1])) 28 self.assertEqual([], p.seqs[2]) 29 30 self.assertEqual(True, p.valid)
31 32
33 - def test_name(self):
34 "_Property.name" 35 p = cssutils.css.property._Property('top', '1px') 36 p.name = 'left' 37 self.assertEqual('left', p.name) 38 39 tests = { 40 u'top': None, 41 u' top': u'top', 42 u'top ': u'top', 43 u' top ': u'top', 44 u'/*x*/ top ': u'top', 45 u' top /*x*/': u'top', 46 u'/*x*/top/*x*/': u'top', 47 u'\\x': None, 48 u'a\\010': None, 49 u'a\\01': None 50 } 51 self.do_equal_r(tests, att='name') 52 53 tests = { 54 u'': xml.dom.SyntaxErr, 55 u' ': xml.dom.SyntaxErr, 56 u'"\n': xml.dom.SyntaxErr, 57 u'/*x*/': xml.dom.SyntaxErr, 58 u':': xml.dom.SyntaxErr, 59 u';': xml.dom.SyntaxErr, 60 u'top:': xml.dom.SyntaxErr, 61 u'top;': xml.dom.SyntaxErr, 62 } 63 self.do_raise_r(tests, att='_setName')
64 65
66 - def test_validate(self):
67 "_Property.name Validating (TEST NOT COMPLETE!)" 68 p = cssutils.css.property._Property('left', '1px') 69 70 # expects message 71 p.name = 'notcss2' 72 73 p.name = 'left' 74 p.value = 'red'
75 76
77 - def test_cssValue(self):
78 "_Property.cssValue" 79 pass
80 #TODO 81 82
83 - def test_priority(self):
84 "_Property.priority" 85 p = cssutils.css.property._Property('top', '1px', '!important') 86 87 p.priority = '' 88 self.assertEqual('', p.priority) 89 90 p.priority = '!important' 91 self.assertEqual('!important', p.priority) 92 93 p.priority = None 94 self.assertEqual('', p.priority) 95 96 p.priority = '! important' 97 self.assertEqual('!important', p.priority) 98 99 100 tests = { 101 u' ': xml.dom.SyntaxErr, 102 u'"\n': xml.dom.SyntaxErr, 103 u'important': xml.dom.SyntaxErr, 104 u';': xml.dom.SyntaxErr, 105 u'!important !important': xml.dom.SyntaxErr 106 } 107 self.do_raise_r(tests, att='_setPriority')
108 109
110 - def test_value(self):
111 "_Property.value (DEPRECATED)" 112 # TODO: extend tests 113 p = cssutils.css.property._Property('top', u'1px') 114 self.assertEqual('1px', p.value) 115 p.value = '2px' 116 self.assertEqual('2px', p.value) 117 118 tests = { 119 u'1px': None, 120 u' 2px': u'2px', 121 u'3px ': u'3px', 122 u' 4px ': u'4px', 123 u'5px 1px': u'5px 1px', 124 } 125 self.do_equal_r(tests, att='value') 126 127 tests = { 128 # no value 129 None: xml.dom.SyntaxErr, 130 u'': xml.dom.SyntaxErr, 131 u' ': xml.dom.SyntaxErr, 132 u'"\n': xml.dom.SyntaxErr, 133 u'/*x*/': xml.dom.SyntaxErr, 134 # not allowed: 135 u':': xml.dom.SyntaxErr, 136 u';': xml.dom.SyntaxErr, 137 u'!important': xml.dom.SyntaxErr, 138 } 139 self.do_raise_r(tests, att='_setValue')
140 141 142 if __name__ == '__main__': 143 import unittest 144 unittest.main() 145