Skip to content
Permalink
Browse files

Get shapefile provider test working again

  • Loading branch information
nyalldawson committed May 13, 2020
1 parent f746db6 commit de2f9f8fa3e5fcb1b94fea64dd300be9fff8fae7
@@ -77,7 +77,7 @@ def assert_query(self, source, expression, expected):
elif expression in self.partiallyCompiledFilters():
self.assertEqual(it.compileStatus(), QgsAbstractFeatureIterator.PartiallyCompiled)
else:
self.assertEqual(it.compileStatus(), QgsAbstractFeatureIterator.Compiled)
self.assertEqual(it.compileStatus(), QgsAbstractFeatureIterator.Compiled, expression)

def runGetFeatureTests(self, source):
FeatureSourceTestCase.runGetFeatureTests(self, source)
@@ -583,11 +583,15 @@ def testAddFeature(self):
self.assertTrue(l.isValid())

f1 = QgsFeature()
f1.setAttributes([6, -220, NULL, 'String', '15', QDateTime(2019, 1, 2, 3, 4, 5), QDate(2019, 1, 2), QTime(3, 4, 5)])
f1.setAttributes([6, -220, NULL, 'String', '15', '2019-01-02 03:04:05' if self.treat_datetime_as_string() else QDateTime(2019, 1, 2, 3, 4, 5),
'2019-01-02' if self.treat_date_as_string() else QDate(2019, 1, 2),
'03:04:05' if self.treat_time_as_string() else QTime(3, 4, 5)])
f1.setGeometry(QgsGeometry.fromWkt('Point (-72.345 71.987)'))

f2 = QgsFeature()
f2.setAttributes([7, 330, 'Coconut', 'CoCoNut', '13', QDateTime(2018, 5, 6, 7, 8, 9), QDate(2018, 5, 6), QTime(7, 8, 9)])
f2.setAttributes([7, 330, 'Coconut', 'CoCoNut', '13', '2018-05-06 07:08:09' if self.treat_datetime_as_string() else QDateTime(2018, 5, 6, 7, 8, 9),
'2018-05-06' if self.treat_date_as_string() else QDate(2018, 5, 6),
'07:08:09' if self.treat_time_as_string() else QTime(7, 8, 9)])

if l.dataProvider().capabilities() & QgsVectorDataProvider.AddFeatures:
# expect success
@@ -676,17 +680,25 @@ def testAddFeatureExtraAttributes(self):
# test that adding features with too many attributes drops these attributes
# we be more tricky and also add a valid feature to stress test the provider
f1 = QgsFeature()
f1.setAttributes([6, -220, NULL, 'String', '15', QDateTime(2019, 1, 2, 3, 4, 5), QDate(2019, 1, 2), QTime(3, 4, 5)])
f1.setAttributes([6, -220, NULL, 'String', '15', '2019-01-02 03:04:05' if self.treat_datetime_as_string() else QDateTime(2019, 1, 2, 3, 4, 5),
'2019-01-02' if self.treat_date_as_string() else QDate(2019, 1, 2),
'03:04:05' if self.treat_time_as_string() else QTime(3, 4, 5)])
f2 = QgsFeature()
f2.setAttributes([7, -230, NULL, 'String', '15', QDateTime(2019, 1, 2, 3, 4, 5), QDate(2019, 1, 2), QTime(3, 4, 5), 15, 16, 17])
f2.setAttributes([7, -230, NULL, 'String', '15', '2019-01-02 03:04:05' if self.treat_datetime_as_string() else QDateTime(2019, 1, 2, 3, 4, 5),
'2019-01-02' if self.treat_date_as_string() else QDate(2019, 1, 2),
'03:04:05' if self.treat_time_as_string() else QTime(3, 4, 5), 15, 16, 17])

result, added = l.dataProvider().addFeatures([f1, f2])
self.assertTrue(result,
'Provider returned False to addFeatures with extra attributes. Providers should accept these features but truncate the extra attributes.')

# make sure feature was added correctly
added = [f for f in l.dataProvider().getFeatures() if f['pk'] == 7][0]
self.assertEqual(added.attributes(), [7, -230, NULL, 'String', '15', QDateTime(2019, 1, 2, 3, 4, 5), QDate(2019, 1, 2), QTime(3, 4, 5)])
self.assertEqual(added.attributes(), [7, -230, NULL, 'String', '15',
'2019-01-02 03:04:05' if self.treat_datetime_as_string() else QDateTime(
2019, 1, 2, 3, 4, 5),
'2019-01-02' if self.treat_date_as_string() else QDate(2019, 1, 2),
'03:04:05' if self.treat_time_as_string() else QTime(3, 4, 5)])

def testAddFeatureWrongGeomType(self):
if not getattr(self, 'getEditableLayer', None):
@@ -87,6 +87,12 @@ def tearDownClass(cls):
for dirname in cls.dirs_to_cleanup:
shutil.rmtree(dirname, True)

def treat_time_as_string(self):
return True

def treat_datetime_as_string(self):
return True

def getSource(self):
tmpdir = tempfile.mkdtemp()
self.dirs_to_cleanup.append(tmpdir)
@@ -202,7 +208,17 @@ def uncompiledFilters(self):
'overlaps(translate($geometry,-1,-1),geom_from_wkt( \'Polygon ((-75.1 76.1, -75.1 81.6, -68.8 81.6, -68.8 76.1, -75.1 76.1))\'))',
'overlaps(buffer($geometry,1),geom_from_wkt( \'Polygon ((-75.1 76.1, -75.1 81.6, -68.8 81.6, -68.8 76.1, -75.1 76.1))\'))',
'intersects(centroid($geometry),geom_from_wkt( \'Polygon ((-74.4 78.2, -74.4 79.1, -66.8 79.1, -66.8 78.2, -74.4 78.2))\'))',
'intersects(point_on_surface($geometry),geom_from_wkt( \'Polygon ((-74.4 78.2, -74.4 79.1, -66.8 79.1, -66.8 78.2, -74.4 78.2))\'))'
'intersects(point_on_surface($geometry),geom_from_wkt( \'Polygon ((-74.4 78.2, -74.4 79.1, -66.8 79.1, -66.8 78.2, -74.4 78.2))\'))',
'"dt" <= format_date(make_datetime(2020, 5, 4, 12, 13, 14), \'yyyy-MM-dd hh:mm:ss\')',
'"dt" < format_date(make_date(2020, 5, 4), \'yyyy-MM-dd hh:mm:ss\')',
'"dt" = format_date(to_datetime(\'000www14ww13ww12www4ww5ww2020\',\'zzzwwwsswwmmwwhhwwwdwwMwwyyyy\'),\'yyyy-MM-dd hh:mm:ss\')',
'"date" <= make_datetime(2020, 5, 4, 12, 13, 14)',
'"date" >= make_date(2020, 5, 4)',
'"date" = to_date(\'www4ww5ww2020\',\'wwwdwwMwwyyyy\')',
'to_time("time") >= make_time(12, 14, 14)',
'to_time("time") = to_time(\'000www14ww13ww12www\',\'zzzwwwsswwmmwwhhwww\')',
'to_datetime("dt", \'yyyy-MM-dd hh:mm:ss\') + make_interval(days:=1) <= make_datetime(2020, 5, 4, 12, 13, 14)',
'to_datetime("dt", \'yyyy-MM-dd hh:mm:ss\') + make_interval(days:=0.01) <= make_datetime(2020, 5, 4, 12, 13, 14)'
])
if int(osgeo.gdal.VersionInfo()[:1]) < 2:
filters.insert('not null')
Binary file not shown.

0 comments on commit de2f9f8

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