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 1175 2008-03-20 17:43:26Z 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          # only possible to set @... similar name
     29          self.assertRaises(xml.dom.InvalidModificationErr, self.r._setAtkeyword, 'x')
     30
     31 -    def test_cssText(self):
     32          "CSSFontFaceRule.cssText"
     33          tests = {
     34              u'@font-face{margin:0;}': u'@font-face {\n    margin: 0\n    }',
     35              u'@font-face  {  margin:0;  }': u'@font-face {\n    margin: 0\n    }',
     36              u'@f\\ont\\-face{margin:0;}': u'@font-face {\n    margin: 0\n    }',
     37              # comments
     38              u'@font-face/*1*//*2*/{margin:0;}':
     39                  u'@font-face /*1*/ /*2*/ {\n    margin: 0\n    }',
     40              # WS
     41              u'@font-face\n\t\f {\n\t\f margin:0;\n\t\f }':
     42                  u'@font-face {\n    margin: 0\n    }',
     43              }
     44          self.do_equal_r(tests)
     45          self.do_equal_p(tests)
     46
     47          tests = {
     48              u'@font-face;': xml.dom.SyntaxErr,
     49              u'@font-face }': xml.dom.SyntaxErr,
     50              }
     51          self.do_raise_p(tests) # parse
     52          tests.update({
     53              u'@font-face {': xml.dom.SyntaxErr, # no }
     54              # trailing
     55              u'@font-face {}1': xml.dom.SyntaxErr,
     56              u'@font-face {}/**/': xml.dom.SyntaxErr,
     57              u'@font-face {} ': xml.dom.SyntaxErr,
     58              })
     59          self.do_raise_r(tests) # set cssText
     60
     61 -    def test_style(self):
     62          "CSSFontFaceRule.style"
     63          d = cssutils.css.CSSStyleDeclaration()
     64          self.r.style = d
     65          self.assertEqual(d.cssText, self.r.style.cssText)
     66          self.assertEqual(None, d.parentRule)
     67
     68 -    def test_properties(self):
     69          "CSSFontFaceRule.style properties"
     70          r = cssutils.css.CSSFontFaceRule()
     71          r.style.cssText = '''
     72          src: url(x)
     73          '''
     74          exp = u'''@font-face {
     75      src: url(x)
     76      }'''
     77          self.assertEqual(exp, r.cssText)
     78
     79 -    def test_incomplete(self):
     80          "CSSFontFaceRule (incomplete)"
     81          tests = {
     82              u'@font-face{':
     83                  u'', # no } and no content
     84              u'@font-face { ':
     85                  u'', # no } and no content
     86              u'@font-face { color: red':
     87                  u'@font-face {\n    color: red\n    }', # no }
     88          }
     89          self.do_equal_p(tests) # parse
     90
     91 -    def test_InvalidModificationErr(self):
     92          "CSSFontFaceRule.cssText InvalidModificationErr"
     93          self._test_InvalidModificationErr(u'@font-face')
     94          tests = {
     95              u'@font-fac {}': xml.dom.InvalidModificationErr,
     96              }
     97          self.do_raise_r(tests)
     98
     99 -    def test_reprANDstr(self):
    100          "CSSFontFaceRule.__repr__(), .__str__()"
    101          style='src: url(x)'
    102          s = cssutils.css.CSSFontFaceRule(style=style)
    103
    104          self.assert_(style in str(s))
    105
    106          s2 = eval(repr(s))
    107          self.assert_(isinstance(s2, s.__class__))
    108          self.assert_(style == s2.style.cssText)
    109
    110
    111  if __name__ == '__main__':
    112      import unittest
    113      unittest.main()
    114