Skip to content

Commit

Permalink
added test for gdal scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Feb 26, 2019
1 parent b10ae55 commit 4383531
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion coretests/tests/packages_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import unittest

from qgis.utils import active_plugins
from qgis.core import QgsVectorLayer, QgsVectorFileWriter
from qgis.core import QgsVectorLayer, QgsVectorFileWriter, QgsProject, QgsRasterLayer, QgsProcessingContext, QgsApplication, QgsProcessingFeedback

from processing.algs.saga.SagaUtils import getInstalledVersion, findSagaFolder
from processing.core.ProcessingConfig import ProcessingConfig
Expand Down Expand Up @@ -55,12 +55,40 @@ def testGeoPackage(self):
'''Test GeoPackage'''
layer = QgsVectorLayer(os.path.join(os.path.dirname(__file__), "data","airports.gpkg"),
"test", "ogr")

self.assertTrue(layer.isValid())
filepath = os.path.join(tempfile.mkdtemp(), str(time.time()) + ".gpkg")
QgsVectorFileWriter.writeAsVectorFormat(layer, filepath, 'utf-8', layer.crs(), 'GPKG')
layer = QgsVectorLayer(filepath, "test", "ogr")
self.assertTrue(layer.isValid())


def testGdalScripts(self):
'''Test GDAL scripts2'''
layer = QgsRasterLayer(os.path.join(os.path.dirname(__file__), "data","dem25.tif"),
"dem")
QgsProject.instance().addMapLayer(layer)
context = QgsProcessingContext()
context.setProject(QgsProject.instance())

alg = QgsApplication.processingRegistry().createAlgorithmById('gdal:rastercalculator')
self.assertIsNotNone(alg)

parameters = {'INPUT_A':'dem',
'BAND_A':1,'INPUT_B':None,'BAND_B':-1,
'INPUT_C':None,'BAND_C':-1,'INPUT_D':None,
'BAND_D':-1,'INPUT_E':None,'BAND_E':-1,
'INPUT_F':None,'BAND_F':-1,'FORMULA':'A*2',
'NO_DATA':None,'RTYPE':5,'OPTIONS':'',
'OUTPUT':'TEMPORARY_OUTPUT'}
feedback = QgsProcessingFeedback()

results, ok = alg.run(parameters, context, feedback)
self.assertTrue(ok)
self.assertTrue(os.path.exists(results["OUTPUT"]))

QgsProject.instance().removeMapLayer(layer)


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

0 comments on commit 4383531

Please sign in to comment.