Skip to content
Permalink
Browse files

test_provider_ogr_gpkg.py format

  • Loading branch information
jgrocha committed Nov 1, 2019
1 parent 5fb4536 commit ded2eee638a16bcfe18751df7be3dd4472755fad
Showing with 13 additions and 16 deletions.
  1. +13 −16 tests/src/python/test_provider_ogr_gpkg.py
@@ -738,22 +738,19 @@ def testReplaceLayerWhileOpen(self):
self.assertEqual(len(features), 1)

def testPkAttributeIndexes(self):
''' Test the primary key index '''
# lyr = ds.CreateLayer('layer', geom_type=ogr.wkbPoint, options=['COLUMN_TYPES=foo=int8,bar=string','GEOMETRY_NAME=the_geom','FID=customfid'])
# lyr = ds.CreateLayer('layer', geom_type=ogr.wkbPoint, options=['GEOMETRY_NAME=the_geom','FID=customfid'])
# lyr = ds.CreateLayer('layer', geom_type=ogr.wkbPoint, options=['GEOMETRY_NAME=the_geom'])
tmpfile = os.path.join(self.basetestpath, 'testPkAttributeIndexes.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
ds.CreateLayer('test', geom_type=ogr.wkbPoint, options=['COLUMN_TYPES=foo=int8,bar=string','GEOMETRY_NAME=the_geom','FID=customfid'])
ds = None
vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile), 'test', 'ogr')
pks = vl.primaryKeyAttributes()
fields = vl.fields()
pkfield = fields.at(pks[0])
self.assertEqual(len(pks), 1)
self.assertEqual(pks[0], 0)
self.assertEqual(pkfield.name(), 'customfid')
self.assertTrue(pkfield.constraints().constraints() & QgsFieldConstraints.ConstraintUnique)
''' Test the primary key index '''
tmpfile = os.path.join(self.basetestpath, 'testPkAttributeIndexes.gpkg')
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile)
ds.CreateLayer('test', geom_type=ogr.wkbPoint, options=['COLUMN_TYPES=foo=int8,bar=string', 'GEOMETRY_NAME=the_geom', 'FID=customfid'])
ds = None
vl = QgsVectorLayer('{}|layerid=0'.format(tmpfile), 'test', 'ogr')
pks = vl.primaryKeyAttributes()
fields = vl.fields()
pkfield = fields.at(pks[0])
self.assertEqual(len(pks), 1)
self.assertEqual(pks[0], 0)
self.assertEqual(pkfield.name(), 'customfid')
self.assertTrue(pkfield.constraints().constraints() & QgsFieldConstraints.ConstraintUnique)

def testSublayerWithComplexLayerName(self):
''' Test reading a gpkg with a sublayer name containing : '''

0 comments on commit ded2eee

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