|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsDateTimeEdit |
| 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__ = 'Denis Rouzaud' |
| 10 | +__date__ = '2018-01-04' |
| 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.gui import QgsDateTimeEdit |
| 18 | +from qgis.PyQt.QtCore import Qt, QDateTime |
| 19 | +from qgis.testing import start_app, unittest |
| 20 | + |
| 21 | +start_app() |
| 22 | + |
| 23 | +DATE = QDateTime.fromString('2018-01-01 01:02:03', Qt.ISODate) |
| 24 | + |
| 25 | + |
| 26 | +class TestQgsDateTimeEdit(unittest.TestCase): |
| 27 | + |
| 28 | + def testSettersGetters(self): |
| 29 | + """ test widget handling of null values """ |
| 30 | + w = qgis.gui.QgsDateTimeEdit() |
| 31 | + w.setAllowNull(False) |
| 32 | + |
| 33 | + w.setDateTime(DATE) |
| 34 | + self.assertEqual(DATE, w.dateTime()) |
| 35 | + # date should remain when setting an invalid date |
| 36 | + w.setDateTime(QDateTime()) |
| 37 | + self.assertEqual(DATE, w.dateTime()) |
| 38 | + |
| 39 | + def testNullValueHandling(self): |
| 40 | + """ test widget handling of null values """ |
| 41 | + w = qgis.gui.QgsDateTimeEdit() |
| 42 | + w.setAllowNull(True) |
| 43 | + |
| 44 | + # date should be valid again when not allowing NULL values |
| 45 | + w.setDateTime(QDateTime()) |
| 46 | + w.setAllowNull(False) |
| 47 | + self.assertTrue(w.dateTime().isValid()) |
| 48 | + |
| 49 | + w.setAllowNull(True) |
| 50 | + w.setDateTime(QDateTime()) |
| 51 | + self.assertFalse(w.dateTime().isValid()) |
| 52 | + |
| 53 | + w.setAllowNull(False) |
| 54 | + self.assertTrue(w.dateTime().isValid()) |
| 55 | + |
| 56 | + |
| 57 | +if __name__ == '__main__': |
| 58 | + unittest.main() |
0 commit comments