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