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 (#27)
by
unknown
01:22
created

tests.test_api.test_compile_raises_ValueError()   A

Complexity

Conditions 5

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 9.3333
c 0
b 0
f 0
cc 5
nop 0
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
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
17
import sass
18
19
# Local imports
20
from . import PROJECT_DIR, EXAMPLES_DIR, example
0 ignored issues
show
Unused Code introduced by
The import PROJECT_DIR seems to be unused.
Loading history...
21
import qtsass
0 ignored issues
show
introduced by
external import "import qtsass" should be placed before "from . import PROJECT_DIR, EXAMPLES_DIR, example"
Loading history...
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():
0 ignored issues
show
Coding Style Naming introduced by
The name test_compile_import_with_include_paths does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
73
    """compile string with include_paths"""
74
75
    qtsass.compile(IMPORT_STR, include_paths=[EXAMPLES_DIR])
76
77
78
def test_compile_raises_ValueError():
0 ignored issues
show
Coding Style Naming introduced by
The name test_compile_raises_ValueError does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
79
    """compile raises ValueError with invalid arguments"""
80
81
    # Pass invalid type to importers - must be sequence
82
    with pytest.raises(ValueError):
83
        qtsass.compile(COLORS_STR, importers=lambda x: None)
84
85
    # Pass invalid type to custom_functions
86
    with pytest.raises(ValueError):
87
        qtsass.compile(COLORS_STR, custom_functions=lambda x: None)
88
89
90
def test_compile_custom_function():
91
    """compile string with custom_functions"""
92
93
    custom_str = (
94
        'QWidget {\n'
95
        '    border: custom_border();\n'
96
        '}'
97
    )
98
99
    def custom_border():
0 ignored issues
show
Coding Style introduced by
This function should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
100
        return '1px solid'
101
102
    css = qtsass.compile(custom_str, custom_functions=[custom_border])
103
    assert '1px solid' in css
104
    assert 'custom_border()' not in css
105
106
107
def test_compile_filename(tmpdir):
108
    """compile_filename simple."""
109
110
    output = tmpdir.join('dummy.css')
111
    qtsass.compile_filename(example('dummy.scss'), output.strpath)
112
    assert exists(output.strpath)
113
114
115
def test_compile_filename_imports(tmpdir):
116
    """compile_filename with imports."""
117
118
    output = tmpdir.join('dark.css')
119
    qtsass.compile_filename(example('complex', 'dark.scss'), output.strpath)
120
    assert exists(output.strpath)
121
122
123
def test_compile_dirname(tmpdir):
124
    """compile_dirname complex."""
125
126
    output = tmpdir.join('complex')
127
    qtsass.compile_dirname(example('complex'), output.strpath)
128
    assert exists(output.join('dark.css').strpath)
129
    assert exists(output.join('light.css').strpath)
130
131
132
def test_watch_raises_ValueError(tmpdir):
0 ignored issues
show
Coding Style Naming introduced by
The name test_watch_raises_ValueError does not conform to the function naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
133
    """watch raises ValueError when source does not exist."""
134
135
    # Watch file does not raise
136
    _ = qtsass.watch(example('dummy.scss'), tmpdir.join('dummy.scss').strpath)
137
138
    # Watch dir does not raise
139
    _ = qtsass.watch(example('complex'), tmpdir.join('complex').strpath)
140
141
    with pytest.raises(ValueError):
142
        _ = qtsass.watch('does_not_exist', 'does_not_exist')
143