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

Source Code for Module cssutils.tests.test_cssstylerule

  1  """testcases for cssutils.css.CSSStyleRuleTestCase""" 
  2  __author__ = '$LastChangedBy: doerwalter $' 
  3  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $' 
  4  __version__ = '0.9.2b2, $LastChangedRevision: 160 $' 
  5   
  6   
  7  import xml.dom 
  8   
  9  import test_cssrule 
 10   
 11  import cssutils 
 12   
 13   
14 -class CSSStyleRuleTestCase(test_cssrule.CSSRuleTestCase):
15
16 - def setUp(self):
17 super(CSSStyleRuleTestCase, self).setUp() 18 self.r = cssutils.css.CSSStyleRule() 19 self.rRO = cssutils.css.CSSStyleRule(readonly=True) 20 self.r_type = cssutils.css.CSSStyleRule.STYLE_RULE
21 22
23 - def test_init(self):
24 "CSSStyleRule.type and init" 25 super(CSSStyleRuleTestCase, self).test_init() 26 self.assertEqual(u'', self.r.cssText) 27 self.assertEqual(cssutils.css.selectorlist.SelectorList, 28 type(self.r.selectorList)) 29 self.assertEqual(u'', self.r.selectorText) 30 self.assertEqual(cssutils.css.CSSStyleDeclaration, 31 type(self.r.style)) 32 self.assertEqual(self.r, self.r.style.parentRule)
33 34
36 "CSSStyleRule.cssText InvalidModificationErr" 37 self._test_InvalidModificationErr(u'a style rule')
38 39
40 - def test_incomplete(self):
41 "CSSStyleRule (incomplete)" 42 tests = { 43 u'a {': u'a {}', # no } 44 u'a { font-family: "arial sans': # no " 45 u'a {\n font-family: "arial sans"\n }', 46 } 47 self.do_equal_p(tests) # parse
48 49
50 - def test_cssText(self):
51 "CSSStyleRule.cssText" 52 tests = { 53 u'''a\n{color: #000}''': 'a {\n color: #000\n }', # issue 4 54 u'''a\n{color: #000000}''': 'a {\n color: #000000\n }', # issue 4 55 u'''a\n{color: #abc}''': 'a {\n color: #abc\n }', # issue 4 56 u'''a\n{color: #abcdef}''': 'a {\n color: #abcdef\n }', # issue 4 57 u'''a\n{color: #00a}''': 'a {\n color: #00a\n }', # issue 4 58 u'''a\n{color: #1a1a1a}''': 'a {\n color: #1a1a1a\n }', # issue 4 59 u'''#id\n{}''': '#id {}', # issue 3 60 u'''* {}''': None, 61 u'a {}': None, 62 u'b { a: 1; }': u'b {\n a: 1\n }', 63 # mix of comments and properties 64 u'c1 {/*1*/a:1;}': u'c1 {\n /*1*/\n a: 1\n }', 65 u'c2 {a:1;/*2*/}': u'c2 {\n a: 1;\n /*2*/\n }', 66 u'd1 {/*0*/}': u'd1 {\n /*0*/\n }', 67 u'd2 {/*0*//*1*/}': u'd2 {\n /*0*/\n /*1*/\n }' 68 } 69 self.do_equal_p(tests) # parse 70 self.do_equal_r(tests) # set cssText 71 72 tests = { 73 u'''a;''': xml.dom.SyntaxErr, 74 u'''a {{}''': xml.dom.SyntaxErr, 75 u'''a }''': xml.dom.SyntaxErr, 76 } 77 self.do_raise_p(tests) # parse 78 tests.update({ 79 u'''a {}x''': xml.dom.SyntaxErr, # trailing 80 u'''/*x*/''': xml.dom.SyntaxErr, 81 u'''a {''': xml.dom.SyntaxErr, 82 }) 83 self.do_raise_r(tests) # set cssText
84 85
86 - def test_selectorList(self):
87 "CSSStyleRule.selectorList" 88 r = cssutils.css.CSSStyleRule() 89 90 r.selectorList.appendSelector(u'a') 91 self.assertEqual(1, r.selectorList.length) 92 self.assertEqual(u'a', r.selectorText) 93 94 r.selectorList.appendSelector(u' b ') 95 # only simple selector! 96 self.assertRaises(xml.dom.InvalidModificationErr, 97 r.selectorList.appendSelector, u' h1, x ') 98 99 self.assertEqual(2, r.selectorList.length) 100 self.assertEqual(u'a, b', r.selectorText)
101 102
103 - def test_selectorText(self):
104 "CSSStyleRule.selectorText" 105 r = cssutils.css.CSSStyleRule() 106 107 r.selectorText = u'a' 108 self.assertEqual(1, r.selectorList.length) 109 self.assertEqual(u'a', r.selectorText) 110 111 r.selectorText = u' b, h1 ' 112 self.assertEqual(2, r.selectorList.length) 113 self.assertEqual(u'b, h1', r.selectorText)
114 115
116 - def test_style(self):
117 "CSSStyleRule.style" 118 d = cssutils.css.CSSStyleDeclaration() 119 self.r.style = d 120 self.assertEqual(d, self.r.style) 121 122 # check if parentRule of sd set 123 self.assertEqual(self.r, d.parentRule)
124 125 126 if __name__ == '__main__': 127 import unittest 128 unittest.main() 129