-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |