1
2 """tests for parsing which does not raise Exceptions normally
3 """
4 __author__ = '$LastChangedBy: cthedot $'
5 __date__ = '$LastChangedDate: 2008-01-12 22:36:38 +0100 (Sa, 12 Jan 2008) $'
6 __version__ = '$LastChangedRevision: 833 $'
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 /* \E4 */'''
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(special_case)"
89 tests = {
90 u'''
91 a[title="a not s\
92 o very long title"] {/*...*/}''': u'''a[title="a not so very long title"] {
93 /*...*/
94 }'''
95 }
96 for css in tests:
97 exp = tests[css]
98 if exp == None:
99 exp = css
100 s = cssutils.parseString(css)
101 self.assertEqual(exp, s.cssText)
102
121
122
124 "cssutils.parseString(href, media)"
125 s = cssutils.parseString("a{}", href="file:foo.css", media="screen, projection, tv")
126 self.assertEqual(s.href, "file:foo.css")
127 self.assertEqual(s.media.mediaText, "screen, projection, tv")
128
129 s = cssutils.parseString("a{}", href="file:foo.css", media=["screen", "projection", "tv"])
130 self.assertEqual(s.media.mediaText, "screen, projection, tv")
131
135
136
137 if __name__ == '__main__':
138 import unittest
139 unittest.main()
140