|
| 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