Skip to content

Commit

Permalink
[sextante] improvements in test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Mar 6, 2013
1 parent d628c2c commit 9ecf823
Show file tree
Hide file tree
Showing 26 changed files with 271 additions and 0 deletions.
53 changes: 53 additions & 0 deletions python/plugins/sextante/gdalwarp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/gdal/warp.py b/gdal/warp.py
index 5dac040..b4f1eee 100644
--- a/gdal/warp.py
+++ b/gdal/warp.py
@@ -23,14 +23,16 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

+import os
+from qgis.core import *
from PyQt4 import QtGui
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.outputs.OutputRaster import OutputRaster
-import os
-from qgis.core import *
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterCrs import ParameterCrs
+from sextante.parameters.ParameterString import ParameterString
+from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.gdal.GdalUtils import GdalUtils

class warp(GeoAlgorithm):
@@ -41,6 +43,8 @@
DEST_SRS = "DEST_SRS "
METHOD = "METHOD"
METHOD_OPTIONS = ["near", "bilinear", "cubic", "cubicspline", "lanczos"]
+ EXTRA = "EXTRA"
+ TR = "TR"

def getIcon(self):
filepath = os.path.dirname(__file__) + "/icons/warp.png"
@@ -52,7 +56,9 @@
self.addParameter(ParameterRaster(warp.INPUT, "Input layer", False))
self.addParameter(ParameterCrs(warp.SOURCE_SRS, "Source SRS (EPSG Code)", "4326"))
self.addParameter(ParameterCrs(warp.DEST_SRS, "Destination SRS (EPSG Code)", "4326"))
+ self.addParameter(ParameterNumber(warp.TR, "Output file resolution in target georeferenced units (leave 0 for no change)", 0.0, None, 0.0))
self.addParameter(ParameterSelection(warp.METHOD, "Resampling method", warp.METHOD_OPTIONS))
+ self.addParameter(ParameterString(warp.EXTRA, "Additional creation parameters"))
self.addOutput(OutputRaster(warp.OUTPUT, "Output layer"))

def processAlgorithm(self, progress):
@@ -68,6 +74,10 @@
commands.append("-of")
out = self.getOutputValue(warp.OUTPUT)
commands.append(GdalUtils.getFormatShortNameFromFilename(out))
+ if str(self.getParameterValue(warp.TR)) != "0":
+ trStr = "-tr "+str(self.getParameterValue(warp.TR))+" "+str(self.getParameterValue(warp.TR))
+ commands.append(trStr)
+ commands.append(str(self.getParameterValue(warp.EXTRA)))
commands.append(self.getParameterValue(warp.INPUT))
commands.append(out)

12 changes: 12 additions & 0 deletions python/plugins/sextante/r_local_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/r/RAlgorithm.py b/r/RAlgorithm.py
index 8b2ea4b..b8e9b35 100644
--- a/r/RAlgorithm.py
+++ b/r/RAlgorithm.py
@@ -276,6 +276,7 @@
commands.append('options("repos"="http://cran.us.r-project.org")')
rLibDir = "%s/rlibs" % SextanteUtils.userFolder().replace("\\","/")
if not os.path.isdir(rLibDir): os.mkdir(rLibDir)
+ commands.append('.libPaths("%s")' % rLibDir )
commands.append(
'tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", lib="%s"))' % rLibDir)
commands.append("library(\"rgdal\")");
21 changes: 21 additions & 0 deletions python/plugins/sextante/tests/GeoAlgorithmTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sextante.core.Sextante import Sextante
from sextante.modeler.ModelerAlgorithm import ModelerAlgorithm

def testAlg(algname, *args):

#test simple execution
alg = Sextante.runAlgorithm(algname, None, *args)
assert alg is not None

out = alg.getOutputValuesAsDictionary()

return out

#test execution in a model

#===========================================================================
# model = ModelerAlgorithm()
# model.addAlgorithm(alg, parametersMap, valuesMap, outputsMap, dependencies)
#===========================================================================

#test
Empty file.
55 changes: 55 additions & 0 deletions python/plugins/sextante/tests/ParametersTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.parameters.ParameterCrs import ParameterCrs

class ParametersTest(unittest.TestCase):

def testParameterNumbert(self):
param = ParameterNumber("name", "desc", 0, 10)
assert not param.setValue("wrongvalue")
assert param.value is None
assert not param.setValue(25)
assert param.value is None
assert param.setValue(5)
assert param.value == 5
assert param.setValue(None)
assert param.value == param.default
s = param.serialize()

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn Nov 11, 2015

Member

@volaya The method serialize() no longer exists. Should this call be replaced with something else (like repr() or unicode) or should the check be removed?

This comment has been minimized.

Copy link
@volaya

volaya Nov 12, 2015

Author Contributor

I think this test for the way-round trip was mainly targeted at the modeler, which had parameters written in a custom format. Now all models are stored as JSON, including its parameters, so no need to test that. I would say we can remove the serialize-deserialize test safely

param2 = ParameterNumber()
param2.deserialize(s)
assert param.default == param2.default
assert param.max == param2.max
assert param.min == param2.min
assert param.description == param2.description
assert param.name == param2.name

def testParameterCRS(self):
param = ParameterCrs("name", "desc")
assert not param.setValue("EPSG:12003")
assert param.value == "EPSG:12003"
assert param.setValue(None)
assert param.value == param.default
s = param.serialize()
param2 = ParameterCrs()
param2.deserialize(s)
assert param.default == param2.default
assert param.description == param2.description
assert param.name == param2.name

def testParameterExtent(self):
param = ParameterCrs("name", "desc")
assert not param.setValue("EPSG:12003")
assert param.value == "EPSG:12003"
assert param.setValue(None)
assert param.value == param.default
s = param.serialize()
param2 = ParameterCrs()
param2.deserialize(s)
assert param.default == param2.default
assert param.description == param2.description
assert param.name == param2.name



if __name__ == '__main__':
unittest.main()
7 changes: 7 additions & 0 deletions python/plugins/sextante/tests/TestData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os.path

dataFolder = os.path.join(os.path.dirname(__file__), 'data')
raster = os.path.join(dataFolder, "raster.tif")
points = os.path.join(dataFolder, "points.shp")
lines = os.path.join(dataFolder, "lines.shp")
polygons = os.path.join(dataFolder, "polygons.shp")
5 changes: 5 additions & 0 deletions python/plugins/sextante/tests/WritersTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'''
Created on 08/02/2013
@author: Volaya
'''
Binary file added python/plugins/sextante/tests/data/lines.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/lines.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50_UTM_zone_30N",GEOGCS["GCS_European_1950",DATUM["D_European_1950",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/lines.qpj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]]
Binary file added python/plugins/sextante/tests/data/lines.shp
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/lines.shx
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/points.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/points.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50_UTM_zone_30N",GEOGCS["GCS_European_1950",DATUM["D_European_1950",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/points.qpj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]]
Binary file added python/plugins/sextante/tests/data/points.shp
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/points.shx
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/polygons.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/polygons.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50_UTM_zone_30N",GEOGCS["GCS_European_1950",DATUM["D_European_1950",SPHEROID["International_1924",6378388,297]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]
1 change: 1 addition & 0 deletions python/plugins/sextante/tests/data/polygons.qpj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["ED50 / UTM zone 30N",GEOGCS["ED50",DATUM["European_Datum_1950",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6230"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4230"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-3],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["EPSG","23030"]]
Binary file added python/plugins/sextante/tests/data/polygons.shp
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/polygons.shx
Binary file not shown.
Binary file added python/plugins/sextante/tests/data/raster.tif
Binary file not shown.
62 changes: 62 additions & 0 deletions python/plugins/sextante/tools/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from sextante.core.Sextante import Sextante
import os
from sextante.core.SextanteUtils import mkdir
from sextante.parameters.ParameterSelection import ParameterSelection

def createBaseHelpFile(alg, folder):
folder = os.path.join(folder, alg.provider.getName().lower())
mkdir(folder)
cmdLineName = alg.commandLineName()[alg.commandLineName().find(":") + 1:].lower()
validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
safeFilename = ''.join(c for c in cmdLineName if c in validChars)
filepath = os.path.join(folder, safeFilename + ".rst")
file = open(filepath, "w")
file.write(alg.name.upper())
file.write("\n")
file.write("=" * len(alg.name))
file.write("\n\n")
file.write("Description\n")
file.write("-----------\n\n")
file.write("Parameters\n")
file.write("----------\n\n")
for param in alg.parameters:
file.write("- ``" + param.description + "[" + param.parameterName()[9:] + "]``:\n")
file.write("\nOutputs\n")
file.write("-------\n\n")
for out in alg.outputs:
file.write("- ``" + out.description + "[" + out.outputTypeName()[6:] + "]``:\n")
file.write("\nSee also\n")
file.write("---------\n\n")
file.write("\nConsole usage\n")
file.write("-------------\n\n")
file.write("\n::\n\n")
s = "\tsextante.runalg('" + alg.commandLineName() + "', "
for param in alg.parameters:
s+= str(param.name.lower().strip()) + ", "
for out in alg.outputs:
if not out.hidden:
s+=str(out.name.lower().strip()) + ", "
s = s[:-2] +")\n"
file.write(s)

s =""
hasSelection = False
for param in alg.parameters:
if isinstance(param, ParameterSelection):
hasSelection = True
s+="\n\t" + param.name.lower() + "(" + param.description + ")\n"
i=0
for option in param.options:
s+= "\t\t" + str(i) + " - " + str(option) + "\n"
i+=1
if hasSelection:
file.write("\n\tAvailable options for selection parameters:\n")
file.write(s)
file.close()


def createBaseHelpFiles(folder):
for provider in Sextante.providers:
for alg in provider.algs:
createBaseHelpFile(alg, folder)

49 changes: 49 additions & 0 deletions python/plugins/sextante/ui/DlgConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'DlgConfig.ui'
#
# Created: Tue Dec 04 00:31:31 2012
# by: PyQt4 UI code generator 4.9.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class Ui_DlgConfig(object):
def setupUi(self, DlgConfig):
DlgConfig.setObjectName(_fromUtf8("DlgConfig"))
DlgConfig.resize(640, 450)
self.verticalLayout = QtGui.QVBoxLayout(DlgConfig)
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.searchBox = QgsFilterLineEdit(DlgConfig)
self.searchBox.setObjectName(_fromUtf8("searchBox"))
self.verticalLayout.addWidget(self.searchBox)
self.tree = QtGui.QTreeWidget(DlgConfig)
self.tree.setAlternatingRowColors(True)
self.tree.setObjectName(_fromUtf8("tree"))
self.verticalLayout.addWidget(self.tree)
self.buttonBox = QtGui.QDialogButtonBox(DlgConfig)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.verticalLayout.addWidget(self.buttonBox)

self.retranslateUi(DlgConfig)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), DlgConfig.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), DlgConfig.reject)
QtCore.QMetaObject.connectSlotsByName(DlgConfig)

def retranslateUi(self, DlgConfig):
DlgConfig.setWindowTitle(QtGui.QApplication.translate("DlgConfig", "SEXTANTE options", None, QtGui.QApplication.UnicodeUTF8))
self.searchBox.setToolTip(QtGui.QApplication.translate("DlgConfig", "Enter setting name to filter list", None, QtGui.QApplication.UnicodeUTF8))
self.tree.headerItem().setText(0, QtGui.QApplication.translate("DlgConfig", "Setting", None, QtGui.QApplication.UnicodeUTF8))
self.tree.headerItem().setText(1, QtGui.QApplication.translate("DlgConfig", "Value", None, QtGui.QApplication.UnicodeUTF8))

from qgis.gui import QgsFilterLineEdit
1 change: 1 addition & 0 deletions python/plugins/sextante/ui/pyuic4.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@"C:\Python27\python" "C:\Python27\Lib\site-packages\PyQt4\uic\pyuic.py" %1 %2 %3 %4 %5 %6 %7 %8 %9

0 comments on commit 9ecf823

Please sign in to comment.