1 """testcases for cssutils.css.CSSRule
2 """
3 __author__ = '$LastChangedBy: cthedot $'
4 __date__ = '$LastChangedDate: 2007-11-25 19:08:50 +0100 (So, 25 Nov 2007) $'
5 __version__ = '$LastChangedRevision: 695 $'
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'@font-face {}',
69 u'@import url(x);',
70 u'@media all {}',
71 u'@namespace "x";'
72 u'@page {}',
73 u'@unknown;',
74 u'a style rule {}'
75 )
76 for test in tests:
77 if startwithspace in (u'a style rule', ) and test in (
78 u'/* comment */', u'a style rule {}'):
79 continue
80
81 if test.startswith(startwithspace):
82 test = u' %s' % test
83
84 self.assertRaises(xml.dom.InvalidModificationErr,
85 self.r._setCssText, test)
86
87
88 if __name__ == '__main__':
89 import unittest
90 unittest.main()
91