Skip to content

Commit

Permalink
test_provider_ogr_gpkg.py format
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrocha committed Nov 1, 2019
1 parent 5fb4536 commit ded2eee
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions tests/src/python/test_provider_ogr_gpkg.py
Expand Up @@ -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 : '''
Expand Down

0 comments on commit ded2eee

Please sign in to comment.