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

# Source Code for Module cssutils.tests.test_cssfontfacerule

      1  """Testcases for cssutils.css.CSSFontFaceRule"""
      2  __version__ = '$Id: test_cssfontfacerule.py 1116 2008-03-05 13:52:23Z cthedot $'
      3
      4  import xml.dom
      5  import test_cssrule
      6  import cssutils
      7
      8 -class CSSFontFaceRuleTestCase(test_cssrule.CSSRuleTestCase):
      9
     10 -    def setUp(self):
     11          super(CSSFontFaceRuleTestCase, self).setUp()
     12          self.r = cssutils.css.CSSFontFaceRule()
     13          self.rRO = cssutils.css.CSSFontFaceRule(readonly=True)
     14          self.r_type = cssutils.css.CSSFontFaceRule.FONT_FACE_RULE#
     15          self.r_typeString = 'FONT_FACE_RULE'
     16
     17 -    def test_init(self):
     18          "CSSFontFaceRule.__init__()"
     19          super(CSSFontFaceRuleTestCase, self).test_init()
     20
     21          r = cssutils.css.CSSFontFaceRule()
     22          self.assertEqual(cssutils.css.CSSStyleDeclaration, type(r.style))
     23          self.assertEqual(r, r.style.parentRule)
     24
     25          # until any properties
     26          self.assertEqual(u'', r.cssText)
     27
     28 -    def test_cssText(self):
     29          "CSSFontFaceRule.cssText"
     30          tests = {
     31              u'@font-face{margin:0;}': u'@font-face {\n    margin: 0\n    }',
     32              u'@font-face  {  margin:0;  }': u'@font-face {\n    margin: 0\n    }',
     33              u'@f\\ont\\-face{margin:0;}': u'@font-face {\n    margin: 0\n    }',
     34              # comments
     35              u'@font-face/*1*//*2*/{margin:0;}':
     36                  u'@font-face /*1*/ /*2*/ {\n    margin: 0\n    }',
     37              # WS
     38              u'@font-face\n\t\f {\n\t\f margin:0;\n\t\f }':
     39                  u'@font-face {\n    margin: 0\n    }',
     40              }
     41          self.do_equal_r(tests)
     42          self.do_equal_p(tests)
     43
     44          tests = {
     45              u'@font-face;': xml.dom.SyntaxErr,
     46              u'@font-face }': xml.dom.SyntaxErr,
     47              }
     48          self.do_raise_p(tests) # parse
     49          tests.update({
     50              u'@font-face {': xml.dom.SyntaxErr, # no }
     51              # trailing
     52              u'@font-face {}1': xml.dom.SyntaxErr,
     53              u'@font-face {}/**/': xml.dom.SyntaxErr,
     54              u'@font-face {} ': xml.dom.SyntaxErr,
     55              })
     56          self.do_raise_r(tests) # set cssText
     57
     58 -    def test_style(self):
     59          "CSSFontFaceRule.style"
     60          d = cssutils.css.CSSStyleDeclaration()
     61          self.r.style = d
     62          self.assertEqual(d.cssText, self.r.style.cssText)
     63          self.assertEqual(None, d.parentRule)
     64
     65 -    def test_properties(self):
     66          "CSSFontFaceRule.style properties"
     67          r = cssutils.css.CSSFontFaceRule()
     68          r.style.cssText = '''
     69          src: url(x)
     70          '''
     71          exp = u'''@font-face {
     72      src: url(x)
     73      }'''
     74          self.assertEqual(exp, r.cssText)
     75
     76 -    def test_incomplete(self):
     77          "CSSFontFaceRule (incomplete)"
     78          tests = {
     79              u'@font-face{':
     80                  u'', # no } and no content
     81              u'@font-face { ':
     82                  u'', # no } and no content
     83              u'@font-face { color: red':
     84                  u'@font-face {\n    color: red\n    }', # no }
     85          }
     86          self.do_equal_p(tests) # parse
     87
     88 -    def test_InvalidModificationErr(self):
     89          "CSSFontFaceRule.cssText InvalidModificationErr"
     90          self._test_InvalidModificationErr(u'@font-face')
     91          tests = {
     92              u'@font-fac {}': xml.dom.InvalidModificationErr,
     93              }
     94          self.do_raise_r(tests)
     95
     96 -    def test_reprANDstr(self):
     97          "CSSFontFaceRule.__repr__(), .__str__()"
     98          style='src: url(x)'
     99          s = cssutils.css.CSSFontFaceRule(style=style)
    100
    101          self.assert_(style in str(s))
    102
    103          s2 = eval(repr(s))
    104          self.assert_(isinstance(s2, s.__class__))
    105          self.assert_(style == s2.style.cssText)
    106
    107
    108  if __name__ == '__main__':
    109      import unittest
    110      unittest.main()
    111