Skip to content

Commit 4089cc5

Browse files
committed
Add test for color button that setting color to transparent
will retain non-alpha color components
1 parent f2b70cf commit 4089cc5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/src/python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
1616
#ADD_PYTHON_TEST(PyQgsAuthenticationSystem test_qgsauthsystem.py)
1717
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
1818
ADD_PYTHON_TEST(PyQgsCategorizedSymbolRendererV2 test_qgscategorizedsymbolrendererv2.py)
19+
ADD_PYTHON_TEST(PyQgsColorButtonV2 test_qgscolorbuttonv2.py)
1920
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
2021
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
2122
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsColorButtonV2.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Nyall Dawson'
10+
__date__ = '25/05/2016'
11+
__copyright__ = 'Copyright 2016, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis # NOQA
16+
17+
from qgis.gui import QgsColorButtonV2
18+
from qgis.testing import start_app, unittest
19+
from qgis.PyQt.QtGui import QColor
20+
start_app()
21+
22+
23+
class TestQgsColorButtonV2(unittest.TestCase):
24+
25+
def testClearingColors(self):
26+
"""
27+
Test setting colors to transparent
28+
"""
29+
30+
# start with a valid color
31+
button = QgsColorButtonV2()
32+
button.setAllowAlpha(True)
33+
button.setColor(QColor(255, 100, 200, 255))
34+
self.assertEqual(button.color(), QColor(255, 100, 200, 255))
35+
36+
# now set to no color
37+
button.setToNoColor()
38+
# ensure that only the alpha channel has changed - not the other color components
39+
self.assertEqual(button.color(), QColor(255, 100, 200, 0))
40+
41+
42+
if __name__ == '__main__':
43+
unittest.main()

0 commit comments

Comments
 (0)