GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#47)
by
unknown
01:06
created

tests.test_api   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 17
eloc 57
dl 0
loc 154
rs 10
c 0
b 0
f 0

11 Functions

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