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