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

Source Code for Module cssutils.tests.test_cssrule

 1  """testcases for cssutils.css.CSSRule 
 2  """ 
 3  __author__ = '$LastChangedBy: doerwalter $' 
 4  __date__ = '$LastChangedDate: 2007-08-02 22:58:23 +0200 (Do, 02 Aug 2007) $' 
 5  __version__ = '0.9.2a2, $LastChangedRevision: 160 $' 
 6   
 7   
 8  import xml.dom 
 9   
10  import basetest 
11   
12  import cssutils.css 
13   
14   
15 -class CSSRuleTestCase(basetest.BaseTestCase):
16 """ 17 base class for all CSSRule subclass tests 18 19 overwrite setUp with the appriopriate values, will be used in 20 test_init and test_readonly 21 overwrite all tests as you please, use:: 22 23 super(CLASSNAME, self).test_TESTNAME(params) 24 25 to use the base class tests too 26 """ 27
28 - def setUp(self):
29 """ 30 OVERWRITE! 31 self.r is the rule 32 self.rRO the readonly rule 33 relf.r_type the type as defined in CSSRule 34 """ 35 super(CSSRuleTestCase, self).setUp() 36 self.r = cssutils.css.CSSRule() 37 self.rRO = cssutils.css.CSSRule() 38 self.rRO._readonly = True # must be set here! 39 self.r_type = cssutils.css.CSSRule.UNKNOWN_RULE
40
41 - def test_init(self):
42 "CSSRule.type and init" 43 self.assertEqual(self.r_type, self.r.type) 44 self.assertEqual(u'', self.r.cssText) 45 self.assertEqual(None, self.r.parentRule) 46 self.assertEqual(None, self.r.parentStyleSheet)
47
48 - def test_readonly(self):
49 "CSSRule readonly" 50 self.assertEqual(True, self.rRO._readonly) 51 self.assertEqual(u'', self.rRO.cssText) 52 self.assertRaises(xml.dom.NoModificationAllowedErr, 53 self.rRO._setCssText, u'x') 54 self.assertEqual(u'', self.rRO.cssText)
55 56
57 - def _test_InvalidModificationErr(self, startwithspace):
58 """ 59 CSSRule.cssText InvalidModificationErr 60 61 called by subclasses 62 63 startwithspace 64 65 for test starting with this not the test but " test" is tested 66 e.g. " @page {}" 67 exception is the style rule test 68 """ 69 tests = (u'', 70 u'/* comment */', 71 u'@charset "utf-8";', 72 u'@import url(x);', 73 u'@media all {}', 74 u'@namespace "x";' 75 u'@page {}', 76 u'@unknown;', 77 u'a style rule {}' 78 ) 79 for test in tests: 80 if startwithspace in (u'a style rule', ) and test in ( 81 u'/* comment */', u'a style rule {}'): 82 continue 83 84 if test.startswith(startwithspace): 85 test = u' %s' % test 86 87 self.assertRaises(xml.dom.InvalidModificationErr, 88 self.r._setCssText, test)
89 90 91 if __name__ == '__main__': 92 import unittest 93 unittest.main() 94