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

Source Code for Module cssutils.tests.test_parse

 1  # -*- coding: utf-8 -*- 
 2  """tests for parsing which does not raise Exceptions normally 
 3  """ 
 4  __author__ = '$LastChangedBy: cthedot $' 
 5  __date__ = '$LastChangedDate: 2007-11-06 22:24:06 +0100 (Di, 06 Nov 2007) $' 
 6  __version__ = '$LastChangedRevision: 654 $' 
 7   
 8  import xml.dom 
 9  import basetest 
10  import cssutils 
11   
12 -class CSSStyleSheetTestCase(basetest.BaseTestCase):
13
14 - def test_roundtrip(self):
15 "cssutils encodings" 16 css1 = ur'''@charset "utf-8"; 17 /* ä */''' 18 s = cssutils.parseString(css1) 19 css2 = unicode(s.cssText, 'utf-8') 20 self.assertEqual(css1, css2) 21 22 s = cssutils.parseString(css2) 23 s.cssRules[0].encoding='ascii' 24 css3 = ur'''@charset "ascii"; 25 /* \0000E4 */''' 26 self.assertEqual(css3, unicode(s.cssText, 'utf-8'))
27
28 - def test_invalidstring(self):
29 "cssutils.parseString(INVALID_STRING)" 30 validfromhere = '@namespace "x";' 31 csss = ( 32 u'''@charset "ascii 33 ;''' + validfromhere, 34 u'''@charset 'ascii 35 ;''' + validfromhere, 36 u'''@namespace "y 37 ;''' + validfromhere, 38 u'''@import "y 39 ;''' + validfromhere, 40 u'''@import url('a 41 );''' + validfromhere, 42 u'''@unknown "y 43 ;''' + validfromhere) 44 for css in csss: 45 s = cssutils.parseString(css) 46 self.assertEqual(validfromhere, s.cssText) 47 48 css = u'''a { font-family: "Courier 49 ; }''' 50 s = cssutils.parseString(css) 51 self.assertEqual(u'', s.cssText)
52
53 - def test_invalid(self):
54 "cssutils.parseString(INVALID_CSS)" 55 tests = { 56 u'a {color: blue}} a{color: red} a{color: green}': 57 u'''a { 58 color: blue 59 } 60 a { 61 color: green 62 }''' 63 } 64 65 for css in tests: 66 exp = tests[css] 67 if exp == None: 68 exp = css 69 s = cssutils.parseString(css) 70 self.assertEqual(exp, s.cssText)
71
72 - def test_attributes(self):
73 "cssutils.parseString(href, media)" 74 s = cssutils.parseString("a{}", href="file:foo.css", media="screen, projection, tv") 75 self.assertEqual(s.href, "file:foo.css") 76 self.assertEqual(s.media.mediaText, "screen, projection, tv") 77 78 s = cssutils.parseString("a{}", href="file:foo.css", media=["screen", "projection", "tv"]) 79 self.assertEqual(s.media.mediaText, "screen, projection, tv")
80
81 - def tearDown(self):
82 # needs to be reenabled here for other tests 83 cssutils.log.raiseExceptions = True
84 85 86 if __name__ == '__main__': 87 import unittest 88 unittest.main() 89