Skip to content
Permalink
Browse files
Update tests
  • Loading branch information
nyalldawson committed Sep 9, 2021
1 parent b8f65cb commit c6e81ab1615d1334436bb051062dde977bb7a0b4
Showing with 14 additions and 13 deletions.
  1. +14 −13 tests/src/python/test_qgsvectorlayertemporalproperties.py
@@ -18,7 +18,8 @@
QgsVectorLayer,
QgsVectorDataProviderTemporalCapabilities,
QgsUnitTypes,
QgsVectorLayerTemporalContext)
QgsVectorLayerTemporalContext,
Qgis)
from qgis.PyQt.QtCore import (QDateTime,
QDate,
QTime,
@@ -276,7 +277,7 @@ def testSingleFieldMode(self):
self.assertEqual(props.createFilterString(context, range), '("start_field" > make_datetime(2019,3,1,11,12,13) AND "start_field" < make_datetime(2020,5,6,8,9,10)) OR "start_field" IS NULL')

# since 3.22 there is also the option to include the end of the feature event
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
# map range [-------------------------)
# feature ranges . . [-------] (false)
# . [-------] (false)
@@ -289,7 +290,7 @@ def testSingleFieldMode(self):
# => start of feature < end of range AND start of feature + duration >= start of range
# OR start of feature < end of range AND start of feature >= start of range - duration
self.assertEqual(props.createFilterString(context, range), '("start_field" >= make_datetime(2019,3,1,11,12,13) AND "start_field" < make_datetime(2020,5,6,8,9,10)) OR "start_field" IS NULL')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default

# different unit
props.setDurationUnits(QgsUnitTypes.TemporalMinutes)
@@ -484,7 +485,7 @@ def testDualFieldMode(self):
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
self.assertEqual(props.createFilterString(context, range), '("start_field" < make_datetime(2020,5,6,8,9,10) OR "start_field" IS NULL) AND ("end_field" > make_datetime(2019,3,4,11,12,13) OR "end_field" IS NULL)')
# since 3.22 there is also the option to include the end of the feature event
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
# map range [-------------------------)
# feature ranges . . [-------] (false)
# . [-------] (false)
@@ -497,7 +498,7 @@ def testDualFieldMode(self):
#
# => start of feature < end of range AND end of feature >= start of range
self.assertEqual(props.createFilterString(context, range), '("start_field" < make_datetime(2020,5,6,8,9,10) OR "start_field" IS NULL) AND ("end_field" >= make_datetime(2019,3,4,11,12,13) OR "end_field" IS NULL)')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default

# features go to +eternity
props.setEndField('')
@@ -597,7 +598,7 @@ def testDualFieldMode(self):
self.assertEqual(props.createFilterString(context, range), '"end_field" > make_datetime(2019,3,4,11,12,13) OR "end_field" IS NULL')
# since 3.22 there is also the option to include the end of the feature event
# => end of feature >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
# map range [-------------------------)
# feature ranges --------.-------------------------.---------] (true)
# --------.-------------------------] (true)
@@ -607,7 +608,7 @@ def testDualFieldMode(self):
#
# => end of feature >= start of range
self.assertEqual(props.createFilterString(context, range), '"end_field" >= make_datetime(2019,3,4,11,12,13) OR "end_field" IS NULL')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default

def testStartAndDurationMode(self):
layer = QgsVectorLayer(
@@ -703,10 +704,10 @@ def testStartAndDurationMode(self):
# [-------] . . (false)
#
# => start of feature < end of range AND start + duration >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
self.assertEqual(props.createFilterString(context, range),
'("start_field" < make_datetime(2020,5,6,8,9,10) OR "start_field" IS NULL) AND (("start_field" + make_interval(0,0,0,0,0,0,"duration"/1000) >= make_datetime(2019,3,4,11,12,13)) OR "duration" IS NULL)')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default

# different units
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)),
@@ -831,9 +832,9 @@ def testExpressionMode(self):
# [-------] . . (false)
#
# => start expression < end of range AND end expression >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
self.assertEqual(props.createFilterString(context, range), '((to_datetime("my string field", \'yyyy MM dd hh::mm:ss\')") < make_datetime(2020,5,6,8,9,10)) AND ((to_datetime("my end field", \'yyyy MM dd hh::mm:ss\')") >= make_datetime(2019,3,4,11,12,13))')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default

# features go to +eternity
props.setEndExpression('')
@@ -937,9 +938,9 @@ def testExpressionMode(self):
# --------] . (true)
# -----] . (false)
# # => end of feature >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginIncludeEnd)
self.assertEqual(props.createFilterString(context, range), '(to_datetime("my end field", \'yyyy MM dd hh::mm:ss\')") >= make_datetime(2019,3,4,11,12,13)')
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginExcludeEnd) # back to default
props.setLimitMode(Qgis.VectorTemporalLimitMode.IncludeBeginExcludeEnd) # back to default


if __name__ == '__main__':

0 comments on commit c6e81ab

Please sign in to comment.