Skip to content
Permalink
Browse files
add tests
  • Loading branch information
alexbruy committed Apr 8, 2017
1 parent 228cc41 commit 792cd6f0838d044064b50b3ec0717c0d913f515c
Showing with 70 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +69 −0 tests/src/python/test_qgscheckablecombobox.py
@@ -20,6 +20,7 @@ ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
ADD_PYTHON_TEST(PyQgsBearingUtils test_qgsbearingutils.py)
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
ADD_PYTHON_TEST(PyQgsCategorizedSymbolRenderer test_qgscategorizedsymbolrenderer.py)
ADD_PYTHON_TEST(PyQgsCheckableComboBox test_qgscheckablecombobox.py)
ADD_PYTHON_TEST(PyQgsColorButton test_qgscolorbutton.py)
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsCheckableComboBox
.. 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__ = 'Alexander Bruy'
__date__ = '22/03/2017'
__copyright__ = 'Copyright 2017, 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.PyQt.QtCore import Qt
from qgis.gui import QgsCheckableComboBox

try:
from qgis.PyQt.QtTest import QSignalSpy
use_signal_spy = True
except:
use_signal_spy = False

from qgis.testing import start_app, unittest

start_app()


class TestQgsCheckableComboBox(unittest.TestCase):

def testGettersSetters(self):
""" test widget getters/setters """
w = qgis.gui.QgsCheckableComboBox()

w.setSeparator('|')
self.assertEqual(w.separator(), '|')
w.setDefaultText('Select items...')
self.assertEqual(w.defaultText(), 'Select items...')

w.addItems(['One', 'Two', 'Three'])

w.setCheckedItems(['Two'])
self.assertEqual(len(w.checkedItems()), 1)
self.assertEqual(w.checkedItems(), ['Two'])
w.setCheckedItems(['Three'])
self.assertEqual(len(w.checkedItems()), 2)
self.assertEqual(w.checkedItems(), ['Two', 'Three'])

w.setItemCheckState(2, Qt.Unchecked)
self.assertEqual(w.itemCheckState(2), Qt.Unchecked)

@unittest.skipIf(not use_signal_spy, "No QSignalSpy available")
def test_ChangedSignals(self):
""" test that signals are correctly emitted when clearing"""

w = qgis.gui.QgsCheckableComboBox()

w.addItems(['One', 'Two', 'Three'])

checkedItemsChanged_spy = QSignalSpy(w.checkedItemsChanged)
w.setCheckedItems(['Two'])

self.assertEqual(len(checkedItemsChanged_spy), 1)


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

0 comments on commit 792cd6f

Please sign in to comment.