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  __version__ = '$Id: test_cssunknownrule.py 1175 2008-03-20 17:43:26Z cthedot $'
      3
      4  import xml.dom
      5  import test_cssrule
      6  import cssutils
      7
      8 -class CSSUnknownRuleTestCase(test_cssrule.CSSRuleTestCase):
      9
     10 -    def setUp(self):
     11          super(CSSUnknownRuleTestCase, self).setUp()
     12          self.r = cssutils.css.CSSUnknownRule()
     13          self.rRO = cssutils.css.CSSUnknownRule(readonly=True)
     14          self.r_type = cssutils.css.CSSUnknownRule.UNKNOWN_RULE
     15          self.r_typeString = 'UNKNOWN_RULE'
     16
     17 -    def test_init(self):
     18          "CSSUnknownRule.type and init"
     19          super(CSSUnknownRuleTestCase, self).test_init()
     20
     21          self.assertFalse(self.r.wellformed)
     22
     23          # only name
     24          r = cssutils.css.CSSUnknownRule(cssText=u'@init;')
     25          self.assertEqual(u'@init', r.atkeyword)
     26          self.assertEqual(u'@init;', r.cssText)
     27          self.assertTrue(r.wellformed)
     28
     29          # @-... not allowed?
     30          r = cssutils.css.CSSUnknownRule(cssText=u'@-init;')
     31          self.assertEqual(u'@-init;', r.cssText)
     32          self.assertEqual(u'@-init', r.atkeyword)
     33          self.assertTrue(r.wellformed)
     34
     35          r = cssutils.css.CSSUnknownRule(cssText=u'@_w-h-a-012;')
     36          self.assertEqual(u'@_w-h-a-012;', r.cssText)
     37          self.assertEqual(u'@_w-h-a-012', r.atkeyword)
     38          self.assertTrue(r.wellformed)
     39
     40          # name and content
     41          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx;')
     42          self.assertEqual(u'@init', r.atkeyword)
     43          self.assertEqual(u'@init xxx;', r.cssText)
     44          self.assertTrue(r.wellformed)
     45
     46          # name and block
     47          r = cssutils.css.CSSUnknownRule(cssText=u'@init { xxx }')
     48          self.assertEqual(u'@init', r.atkeyword)
     49          self.assertEqual(u'@init {\n    xxx\n    }', r.cssText)
     50          self.assertTrue(r.wellformed)
     51
     52          # name and content and block
     53          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx { yyy }')
     54          self.assertEqual(u'@init', r.atkeyword)
     55          self.assertEqual(u'@init xxx {\n    yyy\n    }', r.cssText)
     56          self.assertTrue(r.wellformed)
     57
     58 -    def test_cssText(self):
     59          "CSSUnknownRule.cssText"
     60          tests = {
     61              '@x;': None,
     62              '@x {}': u'@x {\n}',
     63              '@x{ \n \t \f\r}': u'@x {\n}',
     64              '@x {\n    [()]([ {\n    }]) {\n    }\n    }': None,
     65              '@x {\n    @b;\n    }': None,
     66              '''@x {
     67      @b {
     68          x: 1x;
     69          y: 2y;
     70          }
     71      }''': None,
     72              '@x "string" url(x);': None,
     73
     74              # comments
     75              '@x/*1*//*2*/"str"/*3*//*4*/url("x");':
     76                  '@x /*1*/ /*2*/ "str" /*3*/ /*4*/ url(x);',
     77              # WS
     78              '@x"string"url("x");': '@x "string" url(x);',
     79              '@x\n\r\t\f "string"\n\r\t\f url(\n\r\t\f "x"\n\r\t\f )\n\r\t\f ;':
     80                  '@x "string" url(x);',
     81          }
     82          self.do_equal_p(tests)
     83          self.do_equal_r(tests)
     84
     85          tests = {
     86                   u'@;': xml.dom.InvalidModificationErr,
     87                   u'@{}': xml.dom.InvalidModificationErr,
     88                   u'@ ;': xml.dom.InvalidModificationErr,
     89                   u'@ {};': xml.dom.InvalidModificationErr,
     90
     91                   u'@x ;{}': xml.dom.SyntaxErr,
     92                   u'@x ;;': xml.dom.SyntaxErr,
     93                   u'@x }  ': xml.dom.SyntaxErr,
     94                   u'@x }  ;': xml.dom.SyntaxErr,
     95                   u'@x {  ': xml.dom.SyntaxErr,
     96                   u'@x {  ;': xml.dom.SyntaxErr,
     97                   u'@x ': xml.dom.SyntaxErr,
     98                   u'@x (;': xml.dom.SyntaxErr,
     99                   u'@x );': xml.dom.SyntaxErr,
    100                   u'@x [;': xml.dom.SyntaxErr,
    101                   u'@x ];': xml.dom.SyntaxErr,
    102                   u'@x {[(]()}': xml.dom.SyntaxErr,
    103                   # trailing
    104                   u'@x{}{}': xml.dom.SyntaxErr,
    105                   u'@x{};': xml.dom.SyntaxErr,
    106                   u'@x{}1': xml.dom.SyntaxErr,
    107                   u'@x{} ': xml.dom.SyntaxErr,
    108                   u'@x{}/**/': xml.dom.SyntaxErr,
    109                   u'@x;1': xml.dom.SyntaxErr,
    110                   u'@x; ': xml.dom.SyntaxErr,
    111                   u'@x;/**/': xml.dom.SyntaxErr,
    112
    113                   }
    114          self.do_raise_r(tests)
    115
    116 -    def test_InvalidModificationErr(self):
    117          "CSSUnknownRule.cssText InvalidModificationErr"
    118          self._test_InvalidModificationErr(u'@unknown')
    119
    120 -    def test_reprANDstr(self):
    121          "CSSUnknownRule.__repr__(), .__str__()"
    122          s = cssutils.css.CSSUnknownRule(cssText='@x;')
    123
    124          s2 = eval(repr(s))
    125          self.assert_(isinstance(s2, s.__class__))
    126
    127
    128  if __name__ == '__main__':
    129      import unittest
    130      unittest.main()
    131