Skip to content
Permalink
Browse files

[processing] add test for output to GPKG

  • Loading branch information
alexbruy committed May 15, 2018
1 parent 8aa56fc commit 98586461b9a532b180be1d8df8e58f38c9eac66a
Showing with 55 additions and 0 deletions.
  1. +55 −0 python/plugins/processing/tests/Grass7AlgorithmsVectorTest.py
@@ -186,6 +186,61 @@ def testFeatureSourceInput(self):

QgsProject.instance().removeMapLayer(layer)

def testOutputToGeopackage(self):
# create a memory layer and add to project and context
layer = QgsVectorLayer("Point?crs=epsg:3857&field=fldtxt:string&field=fldint:integer",
"testmem", "memory")
self.assertTrue(layer.isValid())
pr = layer.dataProvider()
f = QgsFeature()
f.setAttributes(["test", 123])
f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(100, 200)))
f2 = QgsFeature()
f2.setAttributes(["test2", 457])
f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(110, 200)))
self.assertTrue(pr.addFeatures([f, f2]))
self.assertEqual(layer.featureCount(), 2)
QgsProject.instance().addMapLayer(layer)
context = QgsProcessingContext()
context.setProject(QgsProject.instance())

alg = QgsApplication.processingRegistry().createAlgorithmById('grass7:v.buffer')
self.assertIsNotNone(alg)

temp_file = os.path.join(self.temp_dir, 'grass_output.gpkg')
parameters = {'input': 'testmem',
'cats': '',
'where': '',
'type': [0, 1, 4],
'distance': 1,
'minordistance': None,
'angle': 0,
'column': None,
'scale': 1,
'tolerance': 0.01,
'-s': False,
'-c': False,
'-t': False,
'output': temp_file,
'GRASS_REGION_PARAMETER': None,
'GRASS_SNAP_TOLERANCE_PARAMETER': -1,
'GRASS_MIN_AREA_PARAMETER': 0.0001,
'GRASS_OUTPUT_TYPE_PARAMETER': 0,
'GRASS_VECTOR_DSCO': '',
'GRASS_VECTOR_LCO': ''}
feedback = QgsProcessingFeedback()

results, ok = alg.run(parameters, context, feedback)
self.assertTrue(ok)
self.assertTrue(os.path.exists(temp_file))

# make sure that layer has correct features
res = QgsVectorLayer(temp_file, 'res')
self.assertTrue(res.isValid())
self.assertEqual(res.featureCount(), 2)

QgsProject.instance().removeMapLayer(layer)


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

0 comments on commit 9858646

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