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