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
|
|
|
# Standard library imports |
12
|
|
|
from __future__ import absolute_import |
13
|
|
|
from os.path import exists |
14
|
|
|
|
15
|
|
|
# Third party imports |
16
|
|
|
import pytest |
|
|
|
|
17
|
|
|
import sass |
18
|
|
|
|
19
|
|
|
# Local imports |
20
|
|
|
from . import PROJECT_DIR, EXAMPLES_DIR, example |
|
|
|
|
21
|
|
|
import qtsass |
|
|
|
|
22
|
|
|
|
23
|
|
|
|
24
|
|
|
COLORS_STR = """ |
25
|
|
|
QWidget { |
26
|
|
|
background: rgba(127, 127, 127, 100%); |
27
|
|
|
color: rgb(255, 255, 255); |
28
|
|
|
} |
29
|
|
|
""" |
30
|
|
|
QLINEARGRADIENTS_STR = """ |
31
|
|
|
QWidget { |
32
|
|
|
background: qlineargradient( |
33
|
|
|
x1: 0, |
34
|
|
|
y1: 0, |
35
|
|
|
x2: 0, |
36
|
|
|
y2: 1, |
37
|
|
|
stop: 0.1 blue, |
38
|
|
|
stop: 0.8 green |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
""" |
42
|
|
|
QNOT_STR = """ |
43
|
|
|
QLineEdit:!editable { |
44
|
|
|
background: white; |
45
|
|
|
} |
46
|
|
|
""" |
47
|
|
|
IMPORT_STR = """ |
48
|
|
|
@import 'dummy'; |
49
|
|
|
""" |
50
|
|
|
CUSTOM_BORDER_STR = """ |
51
|
|
|
QWidget { |
52
|
|
|
border: custom_border(); |
53
|
|
|
} |
54
|
|
|
""" |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
def test_compile_strings(): |
58
|
|
|
"""compile various strings.""" |
59
|
|
|
|
60
|
|
|
qtsass.compile(COLORS_STR) |
61
|
|
|
qtsass.compile(QLINEARGRADIENTS_STR) |
62
|
|
|
qtsass.compile(QNOT_STR) |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
def test_compile_import_raises(): |
66
|
|
|
"""compile string with import raises.""" |
67
|
|
|
|
68
|
|
|
with pytest.raises(sass.CompileError): |
69
|
|
|
qtsass.compile(IMPORT_STR) |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
def test_compile_import_with_include_paths(): |
|
|
|
|
73
|
|
|
"""compile string with include_paths""" |
74
|
|
|
|
75
|
|
|
qtsass.compile(IMPORT_STR, include_paths=[EXAMPLES_DIR]) |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
def test_compile_custom_function(): |
79
|
|
|
"""compile string with custom_functions""" |
80
|
|
|
|
81
|
|
|
custom_str = ( |
82
|
|
|
'QWidget {\n' |
83
|
|
|
' border: custom_border();\n' |
84
|
|
|
'}' |
85
|
|
|
) |
86
|
|
|
|
87
|
|
|
def custom_border(): |
|
|
|
|
88
|
|
|
return '1px solid' |
89
|
|
|
|
90
|
|
|
css = qtsass.compile(custom_str, custom_functions=[custom_border]) |
91
|
|
|
assert '1px solid' in css |
92
|
|
|
assert 'custom_border()' not in css |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
def test_compile_filename(tmpdir): |
96
|
|
|
"""compile_filename simple.""" |
97
|
|
|
|
98
|
|
|
output = tmpdir.join('dummy.css') |
99
|
|
|
qtsass.compile_filename(example('dummy.scss'), output.strpath) |
100
|
|
|
assert exists(output.strpath) |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
def test_compile_filename_imports(tmpdir): |
104
|
|
|
"""compile_filename with imports.""" |
105
|
|
|
|
106
|
|
|
output = tmpdir.join('dark.css') |
107
|
|
|
qtsass.compile_filename(example('complex', 'dark.scss'), output.strpath) |
108
|
|
|
assert exists(output.strpath) |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
def test_compile_dirname(tmpdir): |
112
|
|
|
"""compile_dirname complex.""" |
113
|
|
|
|
114
|
|
|
output = tmpdir.join('complex') |
115
|
|
|
qtsass.compile_dirname(example('complex'), output.strpath) |
116
|
|
|
assert exists(output.join('dark.css').strpath) |
117
|
|
|
assert exists(output.join('light.css').strpath) |
118
|
|
|
|