Skip to content
Permalink
Browse files

Test for issue 39230 expressions fields in ogr

  • Loading branch information
elpaso authored and nyalldawson committed Oct 9, 2020
1 parent 47ab231 commit bacd987b06887f4451cd5a80e05abed3ea38a55a
Showing with 50 additions and 6 deletions.
  1. +50 −6 tests/src/python/test_provider_ogr.py
@@ -19,12 +19,23 @@

from osgeo import gdal, ogr # NOQA
from qgis.PyQt.QtCore import QVariant, QByteArray
from qgis.core import (NULL,
QgsApplication,
QgsRectangle,
QgsProviderRegistry,
QgsFeature, QgsFeatureRequest, QgsField, QgsSettings, QgsDataProvider,
QgsVectorDataProvider, QgsVectorLayer, QgsWkbTypes, QgsNetworkAccessManager)
from qgis.core import (
NULL,
QgsApplication,
QgsProject,
QgsField,
QgsFields,
QgsRectangle,
QgsProviderRegistry,
QgsFeature,
QgsFeatureRequest,
QgsSettings,
QgsDataProvider,
QgsVectorDataProvider,
QgsVectorLayer,
QgsWkbTypes,
QgsNetworkAccessManager
)
from qgis.testing import start_app, unittest

from utilities import unitTestDataPath
@@ -780,6 +791,39 @@ def testOpenOptions(self):

os.remove(filename)

def testTransactionGroupExpressionFields(self):
"""Test issue GH #39230, this is not really specific to GPKG"""

project = QgsProject()
project.setAutoTransaction(True)
tmpfile = os.path.join(
self.basetestpath, 'tempGeoPackageTransactionExpressionFields.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
lyr = ds.CreateLayer('test', geom_type=ogr.wkbPoint)
lyr.CreateField(ogr.FieldDefn('str_field', ogr.OFTString))

f = ogr.Feature(lyr.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt('POINT (1 1)'))
f.SetField('str_field', 'one')
lyr.CreateFeature(f)

del lyr
del ds

vl = QgsVectorLayer(tmpfile + '|layername=test', 'test', 'ogr')
f = QgsField('expression_field', QVariant.Int)
idx = vl.addExpressionField('123', f)
self.assertEqual(vl.fields().fieldOrigin(idx), QgsFields.OriginExpression)

project.addMapLayers([vl])

feature = next(vl.getFeatures())
feature.setAttributes([None, 'two', 123])

self.assertTrue(vl.startEditing())
self.assertTrue(vl.addFeature(feature))
self.assertFalse(vl.dataProvider().hasErrors())


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

0 comments on commit bacd987

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