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

# Source Code for Module cssutils.tests.test_cssnamespacerule

      1  """testcases for cssutils.css.CSSImportRule"""
      2  __author__ = '$LastChangedBy: cthedot $'
      3  __date__ = '$LastChangedDate: 2007-08-20 22:09:16 +0200 (Mo, 20 Aug 2007) $'
      4  __version__ = '$LastChangedRevision: 258 $'
      5
      6  import xml.dom
      7  import test_cssrule
      8  import cssutils
      9
     10 -class CSSNamespaceRuleTestCase(test_cssrule.CSSRuleTestCase):
     11
     12 -    def setUp(self):
     13          super(CSSNamespaceRuleTestCase, self).setUp()
     14          self.r = cssutils.css.CSSNamespaceRule()
     15          self.rRO = cssutils.css.CSSNamespaceRule(readonly=True)
     16          self.r_type = cssutils.css.CSSRule.NAMESPACE_RULE
     17          self.r_typeString = 'NAMESPACE_RULE'
     18
     19 -    def test_init(self):
     20          "CSSNamespaceRule.__init__()"
     21          super(CSSNamespaceRuleTestCase, self).test_init()
     22
     23          self.assertEqual(None, self.r.uri)
     24          self.assertEqual(u'', self.r.prefix)
     25          self.assertEqual(u'', self.r.cssText)
     26
     27 -    def test_InvalidModificationErr(self):
     28          "CSSNamespaceRule.cssText InvalidModificationErr"
     29          self._test_InvalidModificationErr(u'@namespace')
     30
     31 -    def test_incomplete(self):
     32          "CSSNamespaceRule (incomplete)"
     33          tests = {
     34              u'@namespace "uri': u'@namespace "uri";'
     35          }
     36          self.do_equal_p(tests) # parse
     37
     38 -    def test_initparameter(self):
     39          "CSSNamespaceRule.__init__(uri=None, prefix=u'')"
     40          r = cssutils.css.CSSNamespaceRule(u'uri', u'prefix')
     41          self.assertEqual(u'uri', r.uri)
     42          self.assertEqual(u'prefix', r.prefix)
     43          self.assertEqual(u'@namespace prefix "uri";', r.cssText)
     44
     45          r = cssutils.css.CSSNamespaceRule(u'uri')
     46          self.assertEqual(u'uri', r.uri)
     47          self.assertEqual(u'', r.prefix)
     48          self.assertEqual(u'@namespace "uri";', r.cssText)
     49
     50 -    def test_uri(self):
     51          "CSSNamespaceRule.uri"
     52          # set
     53          self.r.uri = 'x'
     54          self.assertEqual('x' , self.r.uri)
     55          self.assertEqual(u'@namespace "x";', self.r.cssText)
     56
     57          self.r.uri = '"' # weird but legal
     58          self.assertEqual(u'@namespace "\\"";', self.r.cssText)
     59
     60 -    def test_prefix(self):
     61          "CSSNamespaceRule.prefix"
     62          r = cssutils.css.CSSNamespaceRule()
     63          # set
     64          r.prefix = 'p'
     65          self.assertEqual('p' , r.prefix)
     66          self.assertEqual(u'', r.cssText)
     67          r.uri = 'u'
     68          self.assertEqual('p' , r.prefix)
     69          self.assertEqual(u'@namespace p "u";', r.cssText)
     70
     71 -    def test_cssText(self):
     72          "CSSNamespaceRule.cssText"
     73          tests = {
     74              u'@namespace p "u";': None,
     75              u"@namespace p 'u';": u'@namespace p "u";',
     76
     77              u'@\\namespace p "u";': u'@namespace p "u";',
     78              u'@NAMESPACE p "u";': u'@namespace p "u";',
     79
     80              u'@namespace  p  "u"  ;': u'@namespace p "u";',
     81              u'@namespace p"u";': u'@namespace p "u";',
     82              u'@namespace p "u";': u'@namespace p "u";',
     83
     84              u'@namespace/*1*/p/*2*/"u"/*3*/;': u'@namespace/*1*/ p/*2*/ "u"/*3*/;',
     85
     86              # deprecated
     87              u'@namespace p url(u);': u'@namespace p "u";',
     88              u'@namespace p url(\'u\');': u'@namespace p "u";',
     89              u'@namespace p url(\"u\");': u'@namespace p "u";',
     90              u'@namespace p url( \"u\" );': u'@namespace p "u";',
     91              }
     92          self.do_equal_p(tests)
     93          self.do_equal_r(tests)
     94
     95          tests = {
     96              u'@namespace;': xml.dom.SyntaxErr, # nothing
     97              u'@namespace p;': xml.dom.SyntaxErr, # no uri
     98              u'@namespace "u" p;': xml.dom.SyntaxErr, # order
     99              }
    100          self.do_raise_p(tests) # parse
    101          tests.update({
    102              u'@namespace p url(x)': xml.dom.SyntaxErr, # missing ;
    103              u'@namespace p "u"': xml.dom.SyntaxErr, # missing ;
    104              })
    105          self.do_raise_r(tests) # set cssText
    106
    107 -    def test_reprANDstr(self):
    108          "CSSNamespaceRule.__repr__(), .__str__()"
    109          uri=u'http://example.com'
    110          prefix=u'ex'
    111
    112          s = cssutils.css.CSSNamespaceRule(uri=uri, prefix=prefix)
    113
    114          self.assert_(uri in str(s))
    115          self.assert_(prefix in str(s))
    116
    117          s2 = eval(repr(s))
    118          self.assert_(isinstance(s2, s.__class__))
    119          self.assert_(uri == s2.uri)
    120          self.assert_(prefix == s2.prefix)
    121
    122
    123  if __name__ == '__main__':
    124      import unittest
    125      unittest.main()
    126