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