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-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
    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'@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