Add first set of unit tests

This commit is contained in:
Médéric Ribreux 2016-05-06 12:02:59 +02:00 committed by Médéric RIBREUX
parent ed97ca5628
commit e70f9bcf0c
7 changed files with 327 additions and 4 deletions

View File

@ -558,7 +558,7 @@ class Grass7Algorithm(GeoAlgorithm):
return command
def setSessionProjectionFromProject(self, commands):
if not Grass7Utils.projectionSet:
if not Grass7Utils.projectionSet and iface:
proj4 = iface.mapCanvas().mapSettings().destinationCrs().toProj4()
command = 'g.proj'
command += ' -c'

View File

@ -85,7 +85,6 @@ class AlgorithmsTest:
QgsMapLayerRegistry.instance().removeAllMapLayers()
params = self.load_params(defs['params'])
alg = processing.Processing.getAlgorithm(defs['algorithm']).getCopy()
if isinstance(params, list):
@ -100,7 +99,7 @@ class AlgorithmsTest:
expectFailure = False
if 'expectedFailure' in defs:
exec('\n'.join(defs['expectedFailure'][:-1])) in globals(), locals()
exec(('\n'.join(defs['expectedFailure'][:-1])), globals(), locals())
expectFailure = eval(defs['expectedFailure'][-1])
def doCheck():
@ -174,7 +173,7 @@ class AlgorithmsTest:
if param['type'] == 'vector':
lyr = QgsVectorLayer(filepath, param['name'], 'ogr')
elif param['type'] == 'raster':
lyr = QgsRasterLayer(filepath, param['name'], 'ogr')
lyr = QgsRasterLayer(filepath, param['name'], 'gdal')
self.assertTrue(lyr.isValid(), 'Could not load layer "{}"'.format(filepath))
QgsMapLayerRegistry.instance().addMapLayer(lyr)

View File

@ -9,4 +9,5 @@ IF(ENABLE_TESTS)
ADD_PYTHON_TEST(ProcessingParametersTest ParametersTest.py)
ADD_PYTHON_TEST(ProcessingQgisAlgorithmsTest QgisAlgorithmsTest.py)
ADD_PYTHON_TEST(ProcessingGdalAlgorithmsTest GdalAlgorithmsTest.py)
ADD_PYTHON_TEST(ProcessingGrass7AlgorithmsTest Grass7AlgorithmsTest.py)
ENDIF(ENABLE_TESTS)

View File

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
"""
***************************************************************************
Grass7AlgorithmTests.py
-----------------------
Date : May 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : mederic dot ribreux at medspx dot fr
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Médéric Ribreux'
__date__ = 'May 2016'
__copyright__ = '(C) 2016, Médéric Ribreux'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = ':%H$'
import AlgorithmsTestBase
import nose2
import shutil
from qgis.testing import (
start_app,
unittest
)
class TestGrass7Algorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
@classmethod
def setUpClass(cls):
start_app()
from processing.core.Processing import Processing
Processing.initialize()
cls.cleanup_paths = []
@classmethod
def tearDownClass(cls):
for path in cls.cleanup_paths:
shutil.rmtree(path)
def test_definition_file(self):
return 'grass7_algorithm_tests.yaml'
if __name__ == '__main__':
nose2.main()

View File

@ -0,0 +1,27 @@
<PAMDataset>
<PAMRasterBand band="1">
<Histograms>
<HistItem>
<HistMin>0.625</HistMin>
<HistMax>4.375</HistMax>
<BucketCount>4</BucketCount>
<IncludeOutOfRange>0</IncludeOutOfRange>
<Approximate>0</Approximate>
<HistCounts>300|1700|6000|7000</HistCounts>
</HistItem>
</Histograms>
<Metadata>
<MDI key="COLOR_TABLE_RULES_COUNT">5</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_0">1.000000e+00 1.600000e+00 255 255 0 0 255 0</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_1">1.600000e+00 2.200000e+00 0 255 0 0 255 255</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_2">2.200000e+00 2.800000e+00 0 255 255 0 0 255</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_3">2.800000e+00 3.400000e+00 0 0 255 255 0 255</MDI>
<MDI key="COLOR_TABLE_RULE_RGB_4">3.400000e+00 4.000000e+00 255 0 255 255 0 0</MDI>
<MDI key="Generated_with">GRASS GIS 7.0.3</MDI>
<MDI key="STATISTICS_MAXIMUM">4</MDI>
<MDI key="STATISTICS_MEAN">3.3133333333333</MDI>
<MDI key="STATISTICS_MINIMUM">1</MDI>
<MDI key="STATISTICS_STDDEV">0.74954801195268</MDI>
</Metadata>
</PAMRasterBand>
</PAMDataset>

View File

@ -0,0 +1,238 @@
# See ../README.md for a description of the file format
tests:
# i.* modules
- algorithm: grass7:i.emissivity
name: GRASS7 i.emissivity
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
input:
type: raster
name: custom/grass7/raster_4class.tif
results:
output:
type: rasterhash
hash: 0850127d19d5098ff7cc7bb5991b7881d792e4a64aed42b811cb031b
- algorithm: grass7:i.biomass
name: GRASS7 i.biomass
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
dayofyear:
name: custom/grass7/raster_4class.tif
type: raster
fpar:
name: custom/grass7/raster_4class.tif
type: raster
latitude:
name: custom/grass7/raster_4class.tif
type: raster
lightuse_efficiency:
name: custom/grass7/raster_4class.tif
type: raster
transmissivity_singleway:
name: custom/grass7/raster_4class.tif
type: raster
water_availability:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: 2359a7d0db659ea48272248e663ead0b9cb11e6e97b3fcb14db8bd95
type: rasterhash
- algorithm: grass7:i.eb.eta
name: GRASS7 i.eb.eta
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
evaporativefraction:
name: custom/grass7/raster_4class.tif
type: raster
netradiationdiurnal:
name: custom/grass7/raster_4class.tif
type: raster
temperature:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: ea1b463ce6d426eb3b6d40dbd5b475a010bede837f5a3e3faf3dfb40
type: rasterhash
- algorithm: grass7:i.eb.netrad
name: GRASS7 i.eb.netrad
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
albedo:
name: custom/grass7/raster_4class.tif
type: raster
dayofyear:
name: custom/grass7/raster_4class.tif
type: raster
emissivity:
name: custom/grass7/raster_4class.tif
type: raster
localutctime:
name: custom/grass7/raster_4class.tif
type: raster
ndvi:
name: custom/grass7/raster_4class.tif
type: raster
sunzenithangle:
name: custom/grass7/raster_4class.tif
type: raster
temperature:
name: custom/grass7/raster_4class.tif
type: raster
temperaturedifference2m:
name: custom/grass7/raster_4class.tif
type: raster
transmissivity_singleway:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: d6fc0efa1ebff447b8b04a1bd222acd9e37b1aa3a655ad5b1d69a49f
type: rasterhash
- algorithm: grass7:i.eb.soilheatflux
name: GRASS7 i.eb.soilheatflux
params:
-r: 'False'
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
albedo:
name: custom/grass7/raster_4class.tif
type: raster
localutctime:
name: custom/grass7/raster_4class.tif
type: raster
ndvi:
name: custom/grass7/raster_4class.tif
type: raster
netradiation:
name: custom/grass7/raster_4class.tif
type: raster
temperature:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: b8a09be667e73465a3d06e3c1a1d99a8663f21be1918f498e7b49eca
type: rasterhash
- algorithm: grass7:i.evapo.mh
name: GRASS7 i.evapo.mh
params:
-h: 'True'
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
average_temperature:
name: custom/grass7/raster_4class.tif
type: raster
maximum_temperature:
name: custom/grass7/raster_4class.tif
type: raster
minimum_temperature:
name: custom/grass7/raster_4class.tif
type: raster
netradiation_diurnal:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: 182223a6c8da7b51118794de826c0bc53f288f377351d62aecc63837
type: rasterhash
- algorithm: grass7:i.evapo.pm
name: GRASS7 i.evapo.pm
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
cropheight:
name: custom/grass7/raster_4class.tif
type: raster
elevation:
name: custom/grass7/raster_4class.tif
type: raster
netradiation:
name: custom/grass7/raster_4class.tif
type: raster
relativehumidity:
name: custom/grass7/raster_4class.tif
type: raster
temperature:
name: custom/grass7/raster_4class.tif
type: raster
windspeed:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: 53ad3d55bb9593decb21a6ee10802dd79a42cb17f067ce38ac286ab2
type: rasterhash
- algorithm: grass7:i.evapo.pt
name: GRASS7 i.evapo.pt
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
air_temperature:
name: custom/grass7/raster_4class.tif
type: raster
atmospheric_pressure:
name: custom/grass7/raster_4class.tif
type: raster
net_radiation:
name: custom/grass7/raster_4class.tif
type: raster
priestley_taylor_coeff: 1.26
soil_heatflux:
name: custom/grass7/raster_4class.tif
type: raster
results:
output:
hash: 182223a6c8da7b51118794de826c0bc53f288f377351d62aecc63837
type: rasterhash
- algorithm: grass7:i.topo.coor.ill
name: GRASS7 i.topo.coor.ill
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
azimuth: 50
basemap:
name: custom/grass7/raster_4class.tif
type: raster
zenith: 50
results:
output:
hash: d3da5e4b9d088760d01d70de956d2cd35433c96d175ca68394d4dee8
type: rasterhash
- algorithm: grass7:i.vi
name: GRASS7 i.vi
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
nir:
name: custom/grass7/raster_4class.tif
type: raster
red:
name: custom/grass7/raster_4class.tif
type: raster
storage_bit: 1
viname: 10
results:
output:
hash: 182223a6c8da7b51118794de826c0bc53f288f377351d62aecc63837
type: rasterhash
- algorithm: grass7:i.zc
name: GRASS7 i.zc
params:
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
input:
name: custom/grass7/raster_4class.tif
type: raster
orientations: 1
threshold: 10
width: 9
results:
output:
hash: 270bbef9dd111af5df23a819cb0848e104e0cf4949e794a67fa0b3f2
type: rasterhash