Skip to content

Commit

Permalink
Add test for color button that setting color to transparent
Browse files Browse the repository at this point in the history
will retain non-alpha color components
  • Loading branch information
nyalldawson committed May 25, 2016
1 parent f2b70cf commit 4089cc5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
#ADD_PYTHON_TEST(PyQgsAuthenticationSystem test_qgsauthsystem.py)
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
ADD_PYTHON_TEST(PyQgsCategorizedSymbolRendererV2 test_qgscategorizedsymbolrendererv2.py)
ADD_PYTHON_TEST(PyQgsColorButtonV2 test_qgscolorbuttonv2.py)
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
ADD_PYTHON_TEST(PyQgsComposerEffects test_qgscomposereffects.py)
Expand Down
43 changes: 43 additions & 0 deletions tests/src/python/test_qgscolorbuttonv2.py
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsColorButtonV2.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '25/05/2016'
__copyright__ = 'Copyright 2016, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis # NOQA

from qgis.gui import QgsColorButtonV2
from qgis.testing import start_app, unittest
from qgis.PyQt.QtGui import QColor
start_app()


class TestQgsColorButtonV2(unittest.TestCase):

def testClearingColors(self):
"""
Test setting colors to transparent
"""

# start with a valid color
button = QgsColorButtonV2()
button.setAllowAlpha(True)
button.setColor(QColor(255, 100, 200, 255))
self.assertEqual(button.color(), QColor(255, 100, 200, 255))

# now set to no color
button.setToNoColor()
# ensure that only the alpha channel has changed - not the other color components
self.assertEqual(button.color(), QColor(255, 100, 200, 0))


if __name__ == '__main__':
unittest.main()

0 comments on commit 4089cc5

Please sign in to comment.