Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 9, 2021
1 parent b8f65cb commit c6e81ab
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions tests/src/python/test_qgsvectorlayertemporalproperties.py
Expand Up @@ -18,7 +18,8 @@
QgsVectorLayer,
QgsVectorDataProviderTemporalCapabilities,
QgsUnitTypes,
QgsVectorLayerTemporalContext)
QgsVectorLayerTemporalContext,
Qgis)
from qgis.PyQt.QtCore import (QDateTime,
QDate,
QTime,
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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('')
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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('')
Expand Down Expand Up @@ -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__':
Expand Down

0 comments on commit c6e81ab

Please sign in to comment.