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 custom functions.""" |
10
|
|
|
|
11
|
|
|
from __future__ import absolute_import |
12
|
|
|
|
13
|
|
|
# Standard library imports |
14
|
|
|
import unittest |
15
|
|
|
|
16
|
|
|
# Local imports |
17
|
|
|
from qtsass.api import compile |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class BaseCompileTest(unittest.TestCase): |
21
|
|
|
def compile_scss(self, string): |
22
|
|
|
# NOTE: revise for better future compatibility |
23
|
|
|
wstr = '*{{t: {0};}}'.format(string) |
24
|
|
|
res = compile(wstr) |
25
|
|
|
return res.replace('* {\n t: ', '').replace('; }\n', '') |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class TestRgbaFunc(BaseCompileTest): |
29
|
|
|
def test_rgba(self): |
30
|
|
|
self.assertEqual( |
31
|
|
|
self.compile_scss('rgba(0, 1, 2, 0.3)'), |
32
|
|
|
'rgba(0, 1, 2, 30%)' |
33
|
|
|
) |
34
|
|
|
|
35
|
|
|
def test_rgba_percentage_alpha(self): |
36
|
|
|
result = self.compile_scss('rgba(255, 0, 125, 75%)') |
37
|
|
|
self.assertEqual(result, 'rgba(255, 0, 125, 75%)') |
38
|
|
|
|
39
|
|
|
def test_rgba_8bit_int_alpha(self): |
40
|
|
|
for in_val, out_val in ((0, 0), (128, 50), (255, 100)): |
41
|
|
|
result = self.compile_scss('rgba(255, 0, 125, %i)' % in_val) |
42
|
|
|
self.assertEqual(result, 'rgba(255, 0, 125, %i%%)' % out_val) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class TestQLinearGradientFunc(BaseCompileTest): |
46
|
|
|
def test_color(self): |
47
|
|
|
self.assertEqual( |
48
|
|
|
self.compile_scss('qlineargradient(1, 2, 3, 4, (0 red, 1 blue))'), |
49
|
|
|
'qlineargradient(x1: 1.0, y1: 2.0, x2: 3.0, y2: 4.0, ' |
50
|
|
|
'stop: 0.0 rgba(255, 0, 0, 100%), stop: 1.0 rgba(0, 0, 255, 100%))' |
51
|
|
|
) |
52
|
|
|
|
53
|
|
|
def test_rgba(self): |
54
|
|
|
self.assertEqual( |
55
|
|
|
self.compile_scss('qlineargradient(1, 2, 3, 4, (0 red, 0.2 rgba(5, 6, 7, 0.8)))'), |
56
|
|
|
'qlineargradient(x1: 1.0, y1: 2.0, x2: 3.0, y2: 4.0, ' |
57
|
|
|
'stop: 0.0 rgba(255, 0, 0, 100%), stop: 0.2 rgba(5, 6, 7, 80%))' |
58
|
|
|
) |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
if __name__ == "__main__": |
62
|
|
|
unittest.main(verbosity=2) |
63
|
|
|
|