Skip to content
Permalink
Browse files
Add tests for the inclusion of the Feature event end
  • Loading branch information
rduivenvoorde authored and nyalldawson committed Sep 8, 2021
1 parent 2deb563 commit 51d9eb6390e00edbeec28aac93888dba38d0f577
Showing with 37 additions and 1 deletion.
  1. +37 −1 tests/src/python/test_qgsvectorlayertemporalproperties.py
@@ -258,6 +258,8 @@ def testSingleFieldMode(self):
# 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')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
# and the temporal properties exactly the same
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------)
# feature ranges . . [-------) (false)
@@ -273,6 +275,11 @@ def testSingleFieldMode(self):
# 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')

# since 3.22 there is also the option to include the end of the feature event
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
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

# different unit
props.setDurationUnits(QgsUnitTypes.TemporalMinutes)
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)))
@@ -451,6 +458,7 @@ def testDualFieldMode(self):
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeBeginning=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)')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
# map range [-------------------------)
# feature ranges . . [-------) (false)
# . [-------) (false)
@@ -464,6 +472,11 @@ def testDualFieldMode(self):
# => start of feature < end of range AND end of feature > start of range
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
# => start of feature < end of range AND end of feature >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
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

# features go to +eternity
props.setEndField('')
@@ -501,6 +514,7 @@ def testDualFieldMode(self):
# => start of feature <= end of range
self.assertEqual(props.createFilterString(context, range), '"start_field" <= make_datetime(2020,5,6,8,9,10) OR "start_field" IS NULL')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------)
# feature ranges . . [--------> (false)
@@ -549,8 +563,9 @@ 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')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------]
# map range [-------------------------)
# feature ranges --------.-------------------------.---------) (true)
# --------.-------------------------) (true)
# --------.--------------------) . (true)
@@ -559,6 +574,11 @@ 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')
# 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)
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

def testStartAndDurationMode(self):
layer = QgsVectorLayer(
@@ -627,6 +647,7 @@ def testStartAndDurationMode(self):
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)')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)),
QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------)
@@ -642,6 +663,11 @@ def testStartAndDurationMode(self):
# => start of feature < end of range AND start + duration > 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 (("start_field" + make_interval(0,0,0,0,0,0,"duration"/1000) > make_datetime(2019,3,4,11,12,13)) OR "duration" IS NULL)')
# => start of feature <= end of range AND start + duration > start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
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

# different units
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)),
@@ -741,6 +767,7 @@ def testExpressionMode(self):
# => start expression <= end of range AND end expression > start of range
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))')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------)
# feature ranges . . [-------) (false)
@@ -754,6 +781,10 @@ def testExpressionMode(self):
#
# => start expression < end of range AND end expression > start of range
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))')
# => start expression <= end of range AND end expression > start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
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

# features go to +eternity
props.setEndExpression('')
@@ -839,6 +870,7 @@ def testExpressionMode(self):
# => end of feature > start of range
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)')

# THIS is the QGIS default: using a range with includeBeginning=true en includeEnd=false
range = QgsDateTimeRange(QDateTime(QDate(2019, 3, 4), QTime(11, 12, 13)), QDateTime(QDate(2020, 5, 6), QTime(8, 9, 10)), includeEnd=False)
# map range [-------------------------)
# feature ranges --------.-------------------------.---------) (true)
@@ -849,6 +881,10 @@ def testExpressionMode(self):
#
# => end of feature > start of range
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)')
# => end of feature >= start of range
props.setLimitMode(QgsVectorLayerTemporalProperties.LimitMode.ModeIncludeBeginIncludeEnd)
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


if __name__ == '__main__':

0 comments on commit 51d9eb6

Please sign in to comment.