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: 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
    11 -class CSSRuleTestCase(basetest.BaseTestCase):
    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      """
    23 -    def setUp(self):
    24          """
    25          OVERWRITE!
    26          self.r is the rule
    27          self.rRO the readonly rule
    28          relf.r_type the type as defined in CSSRule
    29          """
    30          super(CSSRuleTestCase, self).setUp()
    31          self.r = cssutils.css.CSSRule()
    32          self.rRO = cssutils.css.CSSRule()
    33          self.rRO._readonly = True # must be set here!
    34          self.r_type = cssutils.css.CSSRule.UNKNOWN_RULE
    35          self.r_typeString = 'UNKNOWN_RULE'
    36
    37 -    def test_init(self):
    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
    45 -    def test_readonly(self):
    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
    53 -    def _test_InvalidModificationErr(self, startwithspace):
    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