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
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 u'@font-face{': 43 u'', # no } and no content 44 u'@font-face { ': 45 u'', # no } and no content 46 u'@font-face { color: red': 47 u'@font-face {\n color: red\n }', # no } 48 } 49 self.do_equal_p(tests) # parse
50
51 - def test_cssText(self):
52 "CSSFontFaceRule.cssText" 53 tests = { 54 u'@font-face {margin:0;}': u'@font-face {\n margin: 0\n }', 55 u'@font-face{margin:0;}': u'@font-face {\n margin: 0\n }', 56 u'@f\\ont\\-face{margin:0;}': u'@font-face {\n margin: 0\n }', 57 u'@font-face/*1*//*2*/{margin:0;}': 58 u'@font-face /*1*/ /*2*/ {\n margin: 0\n }', 59 } 60 self.do_equal_r(tests) 61 self.do_equal_p(tests) 62 63 tests = { 64 u'@font-face;': xml.dom.SyntaxErr, 65 u'@font-face }': xml.dom.SyntaxErr, 66 } 67 self.do_raise_p(tests) # parse 68 tests.update({ 69 u'@font-face {': xml.dom.SyntaxErr, # no } 70 }) 71 self.do_raise_r(tests) # set cssText
72
73 - def test_style(self):
74 "CSSFontFaceRule.style" 75 d = cssutils.css.CSSStyleDeclaration() 76 self.r.style = d 77 self.assertEqual(d, self.r.style) 78 self.assertEqual(self.r, d.parentRule)
79
80 - def test_properties(self):
81 "CSSFontFaceRule.style properties" 82 r = cssutils.css.CSSFontFaceRule() 83 r.style.cssText = ''' 84 src: url(x) 85 ''' 86 exp = u'''@font-face { 87 src: url(x) 88 }''' 89 self.assertEqual(exp, r.cssText)
90
91 - def test_reprANDstr(self):
92 "CSSFontFaceRule.__repr__(), .__str__()" 93 style='src: url(x)' 94 s = cssutils.css.CSSFontFaceRule(style=style) 95 96 self.assert_(style in str(s)) 97 98 s2 = eval(repr(s)) 99 self.assert_(isinstance(s2, s.__class__)) 100 self.assert_(style == s2.style.cssText)
101 102 103 if __name__ == '__main__': 104 import unittest 105 unittest.main() 106