forked from jaraco/cssutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cssunknownrule.py
More file actions
139 lines (119 loc) · 4.69 KB
/
test_cssunknownrule.py
File metadata and controls
139 lines (119 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""testcases for cssutils.css.CSSUnkownRule"""
import xml.dom
import cssutils
from . import test_cssrule
class TestCSSUnknownRule(test_cssrule.TestCSSRule):
def _setup_rule(self):
self.r = cssutils.css.CSSUnknownRule()
self.rRO = cssutils.css.CSSUnknownRule(readonly=True)
self.r_type = cssutils.css.CSSUnknownRule.UNKNOWN_RULE
self.r_typeString = 'UNKNOWN_RULE'
def test_init(self):
"CSSUnknownRule.type and init"
super().test_init()
assert not self.r.wellformed
# only name
r = cssutils.css.CSSUnknownRule(cssText='@init;')
assert '@init' == r.atkeyword
assert '@init;' == r.cssText
assert r.wellformed
# @-... not allowed?
r = cssutils.css.CSSUnknownRule(cssText='@-init;')
assert '@-init;' == r.cssText
assert '@-init' == r.atkeyword
assert r.wellformed
r = cssutils.css.CSSUnknownRule(cssText='@_w-h-a-012;')
assert '@_w-h-a-012;' == r.cssText
assert '@_w-h-a-012' == r.atkeyword
assert r.wellformed
# name and content
r = cssutils.css.CSSUnknownRule(cssText='@init xxx;')
assert '@init' == r.atkeyword
assert '@init xxx;' == r.cssText
assert r.wellformed
# name and block
r = cssutils.css.CSSUnknownRule(cssText='@init { xxx }')
assert '@init' == r.atkeyword
assert '@init {\n xxx\n }' == r.cssText
assert r.wellformed
# name and content and block
r = cssutils.css.CSSUnknownRule(cssText='@init xxx { yyy }')
assert '@init' == r.atkeyword
assert '@init xxx {\n yyy\n }' == r.cssText
assert r.wellformed
def test_cssText(self):
"CSSUnknownRule.cssText"
tests = {
# not normal rules!
'@font-facex{}': '@font-facex {\n }',
'@importurl(x.css);': '@importurl (x . css);',
'@mediaAll{}': '@mediaall {\n }',
'@namespacep"x";': '@namespacep "x";',
'@pageX{}': '@pagex {\n }',
'@xbottom { content: counter(page) }': '@xbottom {\n content: counter(page)\n }',
'@xbottom { content: "x" counter(page) "y"}': '@xbottom {\n content: "x" counter(page) "y"\n }',
}
self.do_equal_p(tests)
# expects the same atkeyword for self.r so do a new one each test
oldr = self.r
for t, e in list(tests.items()):
self.r = cssutils.css.CSSUnknownRule()
self.do_equal_r({t: e})
self.r = oldr
tests = {
'@x;': None,
'@x {}': '@x {\n }',
'@x{ \n \t \f\r}': '@x {\n }',
'@x {\n [()]([ {\n }]) {\n }\n }': None,
'@x {\n @b;\n }': None,
'''@x {
@b {
x: 1x;
y: 2y;
}
}''': None,
'@x "string" url(x);': None,
# comments
'@x/*1*//*2*/"str"/*3*//*4*/url("x");': '@x /*1*/ /*2*/ "str" /*3*/ /*4*/ url(x);',
# WS
'@x"string"url("x");': '@x "string" url(x);',
'@x\n\r\t\f "string"\n\r\t\f url(\n\r\t\f "x"\n\r\t\f )\n\r\t\f ;': '@x "string" url(x);',
}
self.do_equal_p(tests)
self.do_equal_r(tests)
tests = {
'@;': xml.dom.InvalidModificationErr,
'@{}': xml.dom.InvalidModificationErr,
'@ ;': xml.dom.InvalidModificationErr,
'@ {};': xml.dom.InvalidModificationErr,
'@x ;{}': xml.dom.SyntaxErr,
'@x ;;': xml.dom.SyntaxErr,
'@x } ': xml.dom.SyntaxErr,
'@x } ;': xml.dom.SyntaxErr,
'@x { ': xml.dom.SyntaxErr,
'@x { ;': xml.dom.SyntaxErr,
'@x ': xml.dom.SyntaxErr,
'@x (;': xml.dom.SyntaxErr,
'@x );': xml.dom.SyntaxErr,
'@x [;': xml.dom.SyntaxErr,
'@x ];': xml.dom.SyntaxErr,
'@x {[(]()}': xml.dom.SyntaxErr,
# trailing
'@x{}{}': xml.dom.SyntaxErr,
'@x{};': xml.dom.SyntaxErr,
'@x{}1': xml.dom.SyntaxErr,
'@x{} ': xml.dom.SyntaxErr,
'@x{}/**/': xml.dom.SyntaxErr,
'@x;1': xml.dom.SyntaxErr,
'@x; ': xml.dom.SyntaxErr,
'@x;/**/': xml.dom.SyntaxErr,
}
self.do_raise_r(tests)
def test_InvalidModificationErr(self):
"CSSUnknownRule.cssText InvalidModificationErr"
self._test_InvalidModificationErr('@unknown')
def test_reprANDstr(self):
"CSSUnknownRule.__repr__(), .__str__()"
s = cssutils.css.CSSUnknownRule(cssText='@x;')
s2 = eval(repr(s))
assert isinstance(s2, s.__class__)