forked from jaraco/cssutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scripts_csscombine.py
More file actions
64 lines (54 loc) · 2.15 KB
/
test_scripts_csscombine.py
File metadata and controls
64 lines (54 loc) · 2.15 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
"""Testcases for cssutils.scripts.csscombine"""
import cssutils
from cssutils.script import csscombine
from . import basetest
class TestCSSCombine:
C = '@namespace s2"uri";s2|sheet-1{top:1px}s2|sheet-2{top:2px}proxy{top:3px}'
def test_combine(self):
"scripts.csscombine()"
# path, SHOULD be keyword argument!
csspath = basetest.get_sheet_filename('csscombine-proxy.css')
combined = csscombine(csspath)
assert combined == self.C.encode()
combined = csscombine(path=csspath, targetencoding='ascii')
assert combined == ('@charset "ascii";' + self.C).encode()
# url
cssurl = cssutils.helper.path2url(csspath)
combined = csscombine(url=cssurl)
assert combined == self.C.encode()
combined = csscombine(url=cssurl, targetencoding='ascii')
assert combined == ('@charset "ascii";' + self.C).encode()
# cssText
# TODO: really need binary or can handle str too?
f = open(csspath, mode="rb")
cssText = f.read()
f.close()
combined = csscombine(cssText=cssText, href=cssurl)
assert combined == self.C.encode()
combined = csscombine(cssText=cssText, href=cssurl, targetencoding='ascii')
assert combined == ('@charset "ascii";' + self.C).encode()
def test_combine_resolveVariables(self):
"scripts.csscombine(minify=..., resolveVariables=...)"
# no actual imports but checking if minify and resolveVariables work
cssText = '''
@variables {
c: #0f0;
}
a {
color: var(c);
}
'''
# default minify
assert (
csscombine(cssText=cssText, resolveVariables=False)
== b'@variables{c:#0f0}a{color:var(c)}'
)
assert csscombine(cssText=cssText) == b'a{color:#0f0}'
# no minify
assert (
csscombine(cssText=cssText, minify=False, resolveVariables=False)
== b'@variables {\n c: #0f0\n }\na {\n color: var(c)\n }'
)
assert (
csscombine(cssText=cssText, minify=False) == b'a {\n color: #0f0\n }'
)