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: 2008-02-12 23:43:05 +0100 (Di, 12 Feb 2008) $'
      4  __version__ = '$LastChangedRevision: 1049 $'
      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          self.assertFalse(self.r.wellformed)
     24
     25          # only name
     26          r = cssutils.css.CSSUnknownRule(cssText=u'@init;')
     27          self.assertEqual(u'@init', r.atkeyword)
     28          self.assertEqual(u'@init;', r.cssText)
     29          self.assertTrue(r.wellformed)
     30
     31          # @-... not allowed?
     32          r = cssutils.css.CSSUnknownRule(cssText=u'@-init;')
     33          self.assertEqual(u'@-init;', r.cssText)
     34          self.assertEqual(u'@-init', r.atkeyword)
     35          self.assertTrue(r.wellformed)
     36
     37          r = cssutils.css.CSSUnknownRule(cssText=u'@_w-h-a-012;')
     38          self.assertEqual(u'@_w-h-a-012;', r.cssText)
     39          self.assertEqual(u'@_w-h-a-012', r.atkeyword)
     40          self.assertTrue(r.wellformed)
     41
     42          # name and content
     43          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx;')
     44          self.assertEqual(u'@init', r.atkeyword)
     45          self.assertEqual(u'@init xxx;', r.cssText)
     46          self.assertTrue(r.wellformed)
     47
     48          # name and block
     49          r = cssutils.css.CSSUnknownRule(cssText=u'@init { xxx }')
     50          self.assertEqual(u'@init', r.atkeyword)
     51          self.assertEqual(u'@init {\n    xxx\n    }', r.cssText)
     52          self.assertTrue(r.wellformed)
     53
     54          # name and content and block
     55          r = cssutils.css.CSSUnknownRule(cssText=u'@init xxx { yyy }')
     56          self.assertEqual(u'@init', r.atkeyword)
     57          self.assertEqual(u'@init xxx {\n    yyy\n    }', r.cssText)
     58          self.assertTrue(r.wellformed)
     59
     60 -    def test_InvalidModificationErr(self):
     61          "CSSUnknownRule.cssText InvalidModificationErr"
     62          self._test_InvalidModificationErr(u'@unknown')
     63
     64 -    def test_cssText(self):
     65          "CSSUnknownRule.cssText"
     66          tests = {
     67              '@x;': None,
     68              '@x {}': u'@x {\n}',
     69              '@x{ \n \t \f\r}': u'@x {\n}',
     70              '@x {\n    [()]([ {\n    }]) {\n    }\n    }': None,
     71              '@a {\n    @b;\n    }': None,
     72              '''@a {
     73      @b {
     74          x: 1x;
     75          y: 2y;
     76          }
     77      }''': None,
     78              '@x "string" url(x);': None,
     79              "@x'string'url('x');": '@x "string" url(x);',
     80          }
     81          self.do_equal_p(tests)
     82          self.do_equal_r(tests)
     83
     84 -    def test_SyntaxErr(self):
     85          "CSSUnknownRule.cssText"
     86          # at keyword
     87          self.assertRaises(xml.dom.InvalidModificationErr,
     88                            self.r._setCssText, '@;')
     89          self.assertRaises(xml.dom.InvalidModificationErr,
     90                            self.r._setCssText, '@{}')
     91          self.assertRaises(xml.dom.InvalidModificationErr,
     92                            self.r._setCssText, '@ ;')
     93          self.assertRaises(xml.dom.InvalidModificationErr,
     94                            self.r._setCssText, '@ {}')
     95          # rule end
     96          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {}{}')
     97          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {};')
     98          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x ;{}')
     99          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x ;;')
    100          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x }  ')
    101          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x }  ;')
    102          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {  ')
    103          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {  ;')
    104          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x ')
    105          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x (;')
    106          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x );')
    107          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x [;')
    108          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x ];')
    109          self.assertRaises(xml.dom.SyntaxErr, self.r._setCssText, '@x {[(]()}')
    110
    111 -    def test_reprANDstr(self):
    112          "CSSUnknownRule.__repr__(), .__str__()"
    113          s = cssutils.css.CSSUnknownRule(cssText='@x;')
    114
    115          s2 = eval(repr(s))
    116          self.assert_(isinstance(s2, s.__class__))
    117
    118
    119  if __name__ == '__main__':
    120      import unittest
    121      unittest.main()
    122