-
-
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.
Add unit tests for QgsFilterLineEdit, improve docs, add clearValue slot
(cherry-picked from edcc247)
- Loading branch information
1 parent
c022818
commit 109c003
Showing
5 changed files
with
209 additions
and
25 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
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
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,107 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for QgsFilterLineEdit | ||
.. 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__ = 'Nyall Dawson' | ||
__date__ = '20/08/2016' | ||
__copyright__ = 'Copyright 2016, 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.gui import QgsFilterLineEdit | ||
|
||
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 TestQgsFilterLineEdit(unittest.TestCase): | ||
|
||
def testGettersSetters(self): | ||
""" test widget getters/setters """ | ||
w = qgis.gui.QgsFilterLineEdit() | ||
|
||
w.setNullValue('null') | ||
self.assertEqual(w.nullValue(), 'null') | ||
w.setValue('value') | ||
self.assertEqual(w.value(), 'value') | ||
self.assertEqual(w.text(), 'value') | ||
|
||
def testNullValueHandling(self): | ||
""" test widget handling of null values """ | ||
w = qgis.gui.QgsFilterLineEdit() | ||
|
||
# start with no null value | ||
w.setValue(None) | ||
self.assertTrue(w.isNull()) | ||
w.setValue('a') | ||
self.assertEqual(w.text(), 'a') | ||
self.assertFalse(w.isNull()) | ||
|
||
# set a null value | ||
w.setNullValue('null') | ||
self.assertEqual(w.value(), 'a') | ||
self.assertEqual(w.text(), 'a') | ||
self.assertFalse(w.isNull()) | ||
|
||
w.setValue(None) | ||
self.assertTrue(w.isNull()) | ||
self.assertFalse(w.value()) | ||
self.assertEqual(w.text(), 'null') | ||
|
||
w.setValue('null') | ||
self.assertEqual(w.text(), 'null') | ||
# ND: I don't think this following logic is correct - should be a distinction between | ||
# the widget's representation of null and the actual value. Ie isNull() | ||
# should be false and value() should return 'null' | ||
# in other words - if you break this test to match my desired behaviour, feel free to remove it! | ||
self.assertTrue(w.isNull()) | ||
self.assertFalse(w.value()) | ||
|
||
def testClear(self): | ||
""" test clearing widget """ | ||
w = qgis.gui.QgsFilterLineEdit() | ||
|
||
w.setValue('abc') | ||
w.clearValue() | ||
self.assertTrue(w.isNull()) | ||
self.assertFalse(w.value()) | ||
w.clearValue() | ||
self.assertTrue(w.isNull()) | ||
self.assertFalse(w.value()) | ||
|
||
w.setNullValue('def') | ||
w.setValue('abc') | ||
self.assertFalse(w.isNull()) | ||
w.clearValue() | ||
self.assertEqual(w.text(), 'def') | ||
self.assertTrue(w.isNull()) | ||
self.assertFalse(w.value()) | ||
|
||
@unittest.skipIf(not use_signal_spy, "No QSignalSpy available") | ||
def test_ChangedSignals(self): | ||
""" test that signals are correctly emitted when clearing""" | ||
|
||
w = qgis.gui.QgsFilterLineEdit() | ||
|
||
cleared_spy = QSignalSpy(w.cleared) | ||
w.setValue('1') | ||
w.clearValue() | ||
|
||
self.assertEqual(len(cleared_spy), 1) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |