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

# Source Code for Module cssutils.tests.test_cssunknownrule

     1  """testcases for cssutils.css.CSSUnkownRule"""
     2  __author__ = '$LastChangedBy: cthedot $'
     3  __date__ = '$LastChangedDate: 2007-10-19 15:10:03 +0200 (Fr, 19 Okt 2007) $'
     4  __version__ = '$LastChangedRevision: 535 $'
     5
     6  import xml.dom
     7  import test_cssrule
     8  import cssutils
     9
    10 -class CSSUnknownRuleTestCase(test_cssrule.CSSRuleTestCase):
    11
    12 -    def setUp(self):
    13          super(CSSUnknownRuleTestCase, self).setUp()
    14          self.r = cssutils.css.CSSUnknownRule()
    15          self.rRO = cssutils.css.CSSUnknownRule(readonly=True)
    16          self.r_type = cssutils.css.CSSUnknownRule.UNKNOWN_RULE
    17          self.r_typeString = 'UNKNOWN_RULE'
    18
    19 -    def test_init(self):
    20          "CSSUnknownRule.type and init"
    21          super(CSSUnknownRuleTestCase, self).test_init()
    22
    23          # only name
    24          r = cssutils.css.CSSUnknownRule(cssText=u'@init;')
    25          self.assertEqual(u'@init;', r.cssText)
    26
    27          # @-... not allowed?
    28          r = cssutils.css.CSSUnknownRule(cssText=u'@-init;')
    29          self.assertEqual(u'@-init;', r.cssText)
    30
    31          r = cssutils.css.CSSUnknownRule(cssText=u'@_w-h-a-012;')
    32          self.assertEqual(u'@_w-h-a-012;', r.cssText)
    33
    34          # name and content
    35          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx;')
    36          self.assertEqual(u'@init xxx;', r.cssText)
    37
    38          # name and block
    39          r = cssutils.css.CSSUnknownRule(cssText=u'@init { xxx }')
    40          self.assertEqual(u'@init { xxx }', r.cssText)
    41
    42          # name and content and block
    43          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx { yyy }')
    44          self.assertEqual(u'@init xxx { yyy }', r.cssText)
    45
    46 -    def test_InvalidModificationErr(self):
    47          "CSSUnknownRule.cssText InvalidModificationErr"
    48          self._test_InvalidModificationErr(u'@unknown')
    49
    50 -    def test_cssText(self):
    51          "CSSUnknownRule.cssText"
    52          tests = {
    53              '@x;': None,
    54              '@x {}': None,
    55              '''@a {
    56      @b {
    57          x: 1x;
    58          y: 2y;
    59      }
    60  }''': None
    61          }
    62          self.do_equal_p(tests)
    63          self.do_equal_r(tests)
    64
    65 -    def test_SyntaxErr(self):
    66          "CSSUnknownRule.cssText"
    67          # at keyword
    68          self.assertRaises(xml.dom.InvalidModificationErr,
    69                            self.r._setCssText, '@;')
    70          self.assertRaises(xml.dom.InvalidModificationErr,
    71                            self.r._setCssText, '@{}')
    72          self.assertRaises(xml.dom.InvalidModificationErr,
    73                            self.r._setCssText, '@ ;')
    74          self.assertRaises(xml.dom.InvalidModificationErr,
    75                            self.r._setCssText, '@ {}'),
    76          # rule end
    77  #        self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x }  '),
    78  #        self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x }  ;'),
    79  #        self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {  '),
    80  #        self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {  ;'),
    81  #        self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x ')
    82
    83 -    def test_reprANDstr(self):
    84          "CSSUnknownRule.__repr__(), .__str__()"
    85          s = cssutils.css.CSSUnknownRule(cssText='@x;')
    86
    87          s2 = eval(repr(s))
    88          self.assert_(isinstance(s2, s.__class__))
    89
    90
    91  if __name__ == '__main__':
    92      import unittest
    93      unittest.main()
    94