Skip to content

Commit 792cd6f

Browse files
committedApr 8, 2017
add tests
1 parent 228cc41 commit 792cd6f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
 

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ADD_PYTHON_TEST(PyQgsAttributeTableModel test_qgsattributetablemodel.py)
2020
ADD_PYTHON_TEST(PyQgsBearingUtils test_qgsbearingutils.py)
2121
ADD_PYTHON_TEST(PyQgsBlendModes test_qgsblendmodes.py)
2222
ADD_PYTHON_TEST(PyQgsCategorizedSymbolRenderer test_qgscategorizedsymbolrenderer.py)
23+
ADD_PYTHON_TEST(PyQgsCheckableComboBox test_qgscheckablecombobox.py)
2324
ADD_PYTHON_TEST(PyQgsColorButton test_qgscolorbutton.py)
2425
ADD_PYTHON_TEST(PyQgsColorScheme test_qgscolorscheme.py)
2526
ADD_PYTHON_TEST(PyQgsColorSchemeRegistry test_qgscolorschemeregistry.py)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsCheckableComboBox
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__ = 'Alexander Bruy'
10+
__date__ = '22/03/2017'
11+
__copyright__ = 'Copyright 2017, 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.PyQt.QtCore import Qt
18+
from qgis.gui import QgsCheckableComboBox
19+
20+
try:
21+
from qgis.PyQt.QtTest import QSignalSpy
22+
use_signal_spy = True
23+
except:
24+
use_signal_spy = False
25+
26+
from qgis.testing import start_app, unittest
27+
28+
start_app()
29+
30+
31+
class TestQgsCheckableComboBox(unittest.TestCase):
32+
33+
def testGettersSetters(self):
34+
""" test widget getters/setters """
35+
w = qgis.gui.QgsCheckableComboBox()
36+
37+
w.setSeparator('|')
38+
self.assertEqual(w.separator(), '|')
39+
w.setDefaultText('Select items...')
40+
self.assertEqual(w.defaultText(), 'Select items...')
41+
42+
w.addItems(['One', 'Two', 'Three'])
43+
44+
w.setCheckedItems(['Two'])
45+
self.assertEqual(len(w.checkedItems()), 1)
46+
self.assertEqual(w.checkedItems(), ['Two'])
47+
w.setCheckedItems(['Three'])
48+
self.assertEqual(len(w.checkedItems()), 2)
49+
self.assertEqual(w.checkedItems(), ['Two', 'Three'])
50+
51+
w.setItemCheckState(2, Qt.Unchecked)
52+
self.assertEqual(w.itemCheckState(2), Qt.Unchecked)
53+
54+
@unittest.skipIf(not use_signal_spy, "No QSignalSpy available")
55+
def test_ChangedSignals(self):
56+
""" test that signals are correctly emitted when clearing"""
57+
58+
w = qgis.gui.QgsCheckableComboBox()
59+
60+
w.addItems(['One', 'Two', 'Three'])
61+
62+
checkedItemsChanged_spy = QSignalSpy(w.checkedItemsChanged)
63+
w.setCheckedItems(['Two'])
64+
65+
self.assertEqual(len(checkedItemsChanged_spy), 1)
66+
67+
68+
if __name__ == '__main__':
69+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.