|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
# Copyright (c) 2015 Yann Lanthony |
|
4
|
|
|
# Copyright (c) 2017-2018 Spyder Project Contributors |
|
5
|
|
|
# |
|
6
|
|
|
# Licensed under the terms of the MIT License |
|
7
|
|
|
# (See LICENSE.txt for details) |
|
8
|
|
|
# ----------------------------------------------------------------------------- |
|
9
|
|
|
"""Test qtsass api.""" |
|
10
|
|
|
|
|
11
|
|
|
from __future__ import absolute_import |
|
12
|
|
|
|
|
13
|
|
|
# Standard library imports |
|
14
|
|
|
from os.path import exists |
|
15
|
|
|
import logging |
|
16
|
|
|
|
|
17
|
|
|
# Third party imports |
|
18
|
|
|
import pytest |
|
19
|
|
|
import sass |
|
20
|
|
|
|
|
21
|
|
|
# Local imports |
|
22
|
|
|
import qtsass |
|
23
|
|
|
|
|
24
|
|
|
# Local imports |
|
25
|
|
|
from . import EXAMPLES_DIR, PROJECT_DIR, example |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
COLORS_STR = """ |
|
29
|
|
|
QWidget { |
|
30
|
|
|
background: rgba(127, 127, 127, 100%); |
|
31
|
|
|
color: rgb(255, 255, 255); |
|
32
|
|
|
} |
|
33
|
|
|
""" |
|
34
|
|
|
QLINEARGRADIENTS_STR = """ |
|
35
|
|
|
QWidget { |
|
36
|
|
|
background: qlineargradient( |
|
37
|
|
|
x1: 0, |
|
38
|
|
|
y1: 0, |
|
39
|
|
|
x2: 0, |
|
40
|
|
|
y2: 1, |
|
41
|
|
|
stop: 0.1 blue, |
|
42
|
|
|
stop: 0.8 green |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
""" |
|
46
|
|
|
QNOT_STR = """ |
|
47
|
|
|
QLineEdit:!editable { |
|
48
|
|
|
background: white; |
|
49
|
|
|
} |
|
50
|
|
|
""" |
|
51
|
|
|
IMPORT_STR = """ |
|
52
|
|
|
@import 'dummy'; |
|
53
|
|
|
""" |
|
54
|
|
|
CUSTOM_BORDER_STR = """ |
|
55
|
|
|
QWidget { |
|
56
|
|
|
border: custom_border(); |
|
57
|
|
|
} |
|
58
|
|
|
""" |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
def setup_module(): |
|
62
|
|
|
qtsass.enable_logging(level=logging.DEBUG) |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
def teardown_module(): |
|
66
|
|
|
qtsass.enable_logging(level=logging.WARNING) |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
def test_compile_strings(): |
|
70
|
|
|
"""compile various strings.""" |
|
71
|
|
|
|
|
72
|
|
|
qtsass.compile(COLORS_STR) |
|
73
|
|
|
qtsass.compile(QLINEARGRADIENTS_STR) |
|
74
|
|
|
qtsass.compile(QNOT_STR) |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
def test_compile_import_raises(): |
|
78
|
|
|
"""compile string with import raises.""" |
|
79
|
|
|
|
|
80
|
|
|
with pytest.raises(sass.CompileError): |
|
81
|
|
|
qtsass.compile(IMPORT_STR) |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
def test_compile_import_with_include_paths(): |
|
85
|
|
|
"""compile string with include_paths""" |
|
86
|
|
|
|
|
87
|
|
|
qtsass.compile(IMPORT_STR, include_paths=[EXAMPLES_DIR]) |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
def test_compile_raises_ValueError(): |
|
91
|
|
|
"""compile raises ValueError with invalid arguments""" |
|
92
|
|
|
|
|
93
|
|
|
# Pass invalid type to importers - must be sequence |
|
94
|
|
|
with pytest.raises(ValueError): |
|
95
|
|
|
qtsass.compile(COLORS_STR, importers=lambda x: None) |
|
96
|
|
|
|
|
97
|
|
|
# Pass invalid type to custom_functions |
|
98
|
|
|
with pytest.raises(ValueError): |
|
99
|
|
|
qtsass.compile(COLORS_STR, custom_functions=lambda x: None) |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
def test_compile_custom_function(): |
|
103
|
|
|
"""compile string with custom_functions""" |
|
104
|
|
|
|
|
105
|
|
|
custom_str = ( |
|
106
|
|
|
'QWidget {\n' |
|
107
|
|
|
' border: custom_border();\n' |
|
108
|
|
|
'}' |
|
109
|
|
|
) |
|
110
|
|
|
|
|
111
|
|
|
def custom_border(): |
|
112
|
|
|
return '1px solid' |
|
113
|
|
|
|
|
114
|
|
|
css = qtsass.compile(custom_str, custom_functions=[custom_border]) |
|
115
|
|
|
assert '1px solid' in css |
|
116
|
|
|
assert 'custom_border()' not in css |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
def test_compile_filename(tmpdir): |
|
120
|
|
|
"""compile_filename simple.""" |
|
121
|
|
|
|
|
122
|
|
|
output = tmpdir.join('dummy.css') |
|
123
|
|
|
qtsass.compile_filename(example('dummy.scss'), output.strpath) |
|
124
|
|
|
assert exists(output.strpath) |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
def test_compile_filename_imports(tmpdir): |
|
128
|
|
|
"""compile_filename with imports.""" |
|
129
|
|
|
|
|
130
|
|
|
output = tmpdir.join('dark.css') |
|
131
|
|
|
qtsass.compile_filename(example('complex', 'dark.scss'), output.strpath) |
|
132
|
|
|
assert exists(output.strpath) |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
def test_compile_dirname(tmpdir): |
|
136
|
|
|
"""compile_dirname complex.""" |
|
137
|
|
|
|
|
138
|
|
|
output = tmpdir.join('complex') |
|
139
|
|
|
qtsass.compile_dirname(example('complex'), output.strpath) |
|
140
|
|
|
assert exists(output.join('dark.css').strpath) |
|
141
|
|
|
assert exists(output.join('light.css').strpath) |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
def test_watch_raises_ValueError(tmpdir): |
|
145
|
|
|
"""watch raises ValueError when source does not exist.""" |
|
146
|
|
|
|
|
147
|
|
|
# Watch file does not raise |
|
148
|
|
|
_ = qtsass.watch(example('dummy.scss'), tmpdir.join('dummy.scss').strpath) |
|
149
|
|
|
|
|
150
|
|
|
# Watch dir does not raise |
|
151
|
|
|
_ = qtsass.watch(example('complex'), tmpdir.join('complex').strpath) |
|
152
|
|
|
|
|
153
|
|
|
with pytest.raises(ValueError): |
|
154
|
|
|
_ = qtsass.watch('does_not_exist', 'does_not_exist') |
|
155
|
|
|
|