Skip to content
Permalink
Browse files

add test for date/time edit

  • Loading branch information
3nids committed Jan 5, 2018
1 parent ed2f056 commit d7b4bffdc8bc680a13608a1c47e2e16e731a1c36
Showing with 59 additions and 0 deletions.
  1. +1 −0 tests/src/python/CMakeLists.txt
  2. +58 −0 tests/src/python/test_qgsdatetimeedit.py
@@ -44,6 +44,7 @@ ADD_PYTHON_TEST(PyQgsCoordinateTransformContext test_qgscoordinatetransformconte
ADD_PYTHON_TEST(PyQgsDefaultValue test_qgsdefaultvalue.py)
ADD_PYTHON_TEST(PyQgsXmlUtils test_qgsxmlutils.py)
ADD_PYTHON_TEST(PyQgsCoordinateTransform test_qgscoordinatetransform.py)
ADD_PYTHON_TEST(PyQgsDateTimeEdit test_qgsdatetimeedit.py)
ADD_PYTHON_TEST(PyQgsDateTimeStatisticalSummary test_qgsdatetimestatisticalsummary.py)
ADD_PYTHON_TEST(PyQgsDelimitedTextProvider test_qgsdelimitedtextprovider.py)
ADD_PYTHON_TEST(PyQgsDistanceArea test_qgsdistancearea.py)
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for QgsDateTimeEdit
.. 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__ = 'Denis Rouzaud'
__date__ = '2018-01-04'
__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.gui import QgsDateTimeEdit
from qgis.PyQt.QtCore import Qt, QDateTime
from qgis.testing import start_app, unittest

start_app()

DATE = QDateTime.fromString('2018-01-01 01:02:03', Qt.ISODate)


class TestQgsDateTimeEdit(unittest.TestCase):

def testSettersGetters(self):
""" test widget handling of null values """
w = qgis.gui.QgsDateTimeEdit()
w.setAllowNull(False)

w.setDateTime(DATE)
self.assertEqual(DATE, w.dateTime())
# date should remain when setting an invalid date
w.setDateTime(QDateTime())
self.assertEqual(DATE, w.dateTime())

def testNullValueHandling(self):
""" test widget handling of null values """
w = qgis.gui.QgsDateTimeEdit()
w.setAllowNull(True)

# date should be valid again when not allowing NULL values
w.setDateTime(QDateTime())
w.setAllowNull(False)
self.assertTrue(w.dateTime().isValid())

w.setAllowNull(True)
w.setDateTime(QDateTime())
self.assertFalse(w.dateTime().isValid())

w.setAllowNull(False)
self.assertTrue(w.dateTime().isValid())


if __name__ == '__main__':
unittest.main()

0 comments on commit d7b4bff

Please sign in to comment.
You can’t perform that action at this time.