1
2 """tests for parsing which does not raise Exceptions normally
3 """
4 __author__ = '$LastChangedBy: cthedot $'
5 __date__ = '$LastChangedDate: 2007-11-24 23:35:19 +0100 (Sa, 24 Nov 2007) $'
6 __version__ = '$LastChangedRevision: 685 $'
7
8 import xml.dom
9 import basetest
10 import cssutils
11
13
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
29 "cssutils escapes"
30 css = ur'\43\x { \43\x: \43\x !import\41nt }'
31 sheet = cssutils.parseString(css)
32 self.assertEqual(sheet.cssText, ur'''C\x {
33 c\x: C\x !important
34 }''')
35
36 css = ur'\ x{\ x :\ x ;y:1} '
37 sheet = cssutils.parseString(css)
38 self.assertEqual(sheet.cssText, ur'''\ x {
39 \ x: \ x;
40 y: 1
41 }''')
42
44 "cssutils.parseString(INVALID_STRING)"
45 validfromhere = '@namespace "x";'
46 csss = (
47 u'''@charset "ascii
48 ;''' + validfromhere,
49 u'''@charset 'ascii
50 ;''' + validfromhere,
51 u'''@namespace "y
52 ;''' + validfromhere,
53 u'''@import "y
54 ;''' + validfromhere,
55 u'''@import url('a
56 );''' + validfromhere,
57 u'''@unknown "y
58 ;''' + validfromhere)
59 for css in csss:
60 s = cssutils.parseString(css)
61 self.assertEqual(validfromhere, s.cssText)
62
63 css = u'''a { font-family: "Courier
64 ; }'''
65 s = cssutils.parseString(css)
66 self.assertEqual(u'', s.cssText)
67
69 "cssutils.parseString(INVALID_CSS)"
70 tests = {
71 u'a {color: blue}} a{color: red} a{color: green}':
72 u'''a {
73 color: blue
74 }
75 a {
76 color: green
77 }'''
78 }
79
80 for css in tests:
81 exp = tests[css]
82 if exp == None:
83 exp = css
84 s = cssutils.parseString(css)
85 self.assertEqual(exp, s.cssText)
86
88 "cssutils.parseString(href, media)"
89 s = cssutils.parseString("a{}", href="file:foo.css", media="screen, projection, tv")
90 self.assertEqual(s.href, "file:foo.css")
91 self.assertEqual(s.media.mediaText, "screen, projection, tv")
92
93 s = cssutils.parseString("a{}", href="file:foo.css", media=["screen", "projection", "tv"])
94 self.assertEqual(s.media.mediaText, "screen, projection, tv")
95
99
100
101 if __name__ == '__main__':
102 import unittest
103 unittest.main()
104