Skip to content
Permalink
Browse files

Basic test suite.

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@276 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com
cpolymeris@gmail.com committed Jun 30, 2012
1 parent 3c18386 commit 0d475df0e5771bd8a63e95f259c88229a3b10e53
@@ -0,0 +1,68 @@
NAME:Watersheds from DEM and threshold
GROUP:Hydrology
PARAMETER:ParameterRaster|RASTERLAYER_DEM|DEM|False
120.0,60.0
PARAMETER:ParameterNumber|NUMBER_THRESHOLD|Threshold|0.0|None|1000000.0
610.0,61.0
VALUE:HARDCODEDPARAMVALUE_CLASS_ID_3=0
VALUE:HARDCODEDPARAMVALUE_SPLIT_3=0
VALUE:HARDCODEDPARAMVALUE_Method_0=0
VALUE:HARDCODEDPARAMVALUE_INIT_METHOD_1=2
VALUE:HARDCODEDPARAMVALUE_STEP_0=1
VALUE:HARDCODEDPARAMVALUE_CONVERGENCE_0=1.0
VALUE:HARDCODEDPARAMVALUE_DOLINEAR _0=True
VALUE:HARDCODEDPARAMVALUE_MINSIZE_2=0
VALUE:HARDCODEDPARAMVALUE_CLASS_ALL_3=1
VALUE:HARDCODEDPARAMVALUE_LINEARTHRS_0=500.0
VALUE:HARDCODEDPARAMVALUE_MINLEN_1=10.0
VALUE:HARDCODEDPARAMVALUE_DIV_CELLS_1=10.0
ALGORITHM:saga:catchmentarea(parallel)
288.0,259.0
-1|RASTERLAYER_DEM
None
None
None
None
-1|HARDCODEDPARAMVALUE_STEP_0
-1|HARDCODEDPARAMVALUE_Method_0
-1|HARDCODEDPARAMVALUE_DOLINEAR _0
-1|HARDCODEDPARAMVALUE_LINEARTHRS_0
None
None
-1|HARDCODEDPARAMVALUE_CONVERGENCE_0
None
None
None
None
None
None
None
None
ALGORITHM:saga:channelnetwork
601.0,242.0
-1|RASTERLAYER_DEM
None
0|CAREA
-1|HARDCODEDPARAMVALUE_INIT_METHOD_1
-1|NUMBER_THRESHOLD
None
-1|HARDCODEDPARAMVALUE_DIV_CELLS_1
None
-1|HARDCODEDPARAMVALUE_MINLEN_1
None
None
None
ALGORITHM:saga:watershedbasins
140.0,534.0
-1|RASTERLAYER_DEM
1|CHNLNTWRK
None
-1|HARDCODEDPARAMVALUE_MINSIZE_2
None
ALGORITHM:saga:vectorisinggridclasses
550.0,530.0
2|BASINS
-1|HARDCODEDPARAMVALUE_CLASS_ALL_3
-1|HARDCODEDPARAMVALUE_CLASS_ID_3
-1|HARDCODEDPARAMVALUE_SPLIT_3
Watersheds
@@ -0,0 +1,94 @@
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**QGIS plugin implementation.**
Contact : ole.moller.nielsen@gmail.com
.. note:: 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.
.. note:: This source code was copied from the 'postgis viewer' application
with original authors:
Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk
Copyright (c) 2011 German Carrillo, geotux_tuxman@linuxmail.org
"""

__author__ = 'tim@linfiniti.com'
__version__ = '0.3.0'
__date__ = '10/01/2011'
__copyright__ = ('Copyright (c) 2010 by Ivan Mincik, ivan.mincik@gista.sk and '
'Copyright (c) 2011 German Carrillo, '
'geotux_tuxman@linuxmail.org')


from PyQt4.QtCore import QObject
from qgis.core import QgsMapLayerRegistry


class QgisInterface(QObject):
"""Class to expose qgis objects and functionalities to plugins.
This class is here for enabling us to run unit tests only,
so most methods are simply stubs.
"""

def __init__(self, canvas):
"""Constructor"""
QObject.__init__(self)
self.canvas = canvas

def zoomFull(self):
"""Zoom to the map full extent"""
pass

def zoomToPrevious(self):
"""Zoom to previous view extent"""
pass

def zoomToNext(self):
"""Zoom to next view extent"""
pass

def addVectorLayer(self, vectorLayerPath, baseName, providerKey):
"""Add a vector layer"""
pass

def addRasterLayer(self, rasterLayerPath, baseName):
"""Add a raster layer given a raster layer file name"""
pass

def activeLayer(self):
"""Get pointer to the active layer (layer selected in the legend)"""
myLayers = QgsMapLayerRegistry.instance().mapLayers()
for myItem in myLayers:
return myLayers[myItem]

def addToolBarIcon(self, qAction):
"""Add an icon to the plugins toolbar"""
pass

def removeToolBarIcon(self, qAction):
"""Remove an action (icon) from the plugin toolbar"""
pass

def addToolBar(self, name):
"""Add toolbar with specified name"""
pass

def mapCanvas(self):
"""Return a pointer to the map canvas"""
return self.canvas

def mainWindow(self):
"""Return a pointer to the main window
In case of QGIS it returns an instance of QgisApp
"""
pass

def addDockWidget(self, area, dockwidget):
""" Add a dock widget to the main window """
pass
@@ -0,0 +1 @@
PYTHONPATH=~/.qgis/python/plugins/:~/Proyectos/qgis/output/python/:~/Proyectos/qgis/python/plugins/ python test.py
@@ -0,0 +1,58 @@
"""
InaSAFE Disaster risk assessment tool developed by AusAid -
**QGIS plugin test suite.**
Contact : ole.moller.nielsen@gmail.com
.. note:: 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__ = 'tim@linfiniti.com'
__version__ = '0.3.0'
__date__ = '10/01/2011'
__copyright__ = ('Copyright 2012, Australia Indonesia Facility for '
'Disaster Reduction')

import unittest
import sys
import os

# Add parent directory to path to make test aware of other modules
pardir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(pardir)

sys.path.append('/usr/share/qgis/python/plugins')

from qgis.gui import QgsMapCanvas
from qgis_interface import QgisInterface
from PyQt4.QtGui import QWidget
from utilities_test import getQgisTestApp
#from gui.is_plugin import ISPlugin
from sextante import SextantePlugin
from sextante.core.Sextante import Sextante
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()


class SextantePluginTest(unittest.TestCase):
"""Test suite for Sextante QGis plugin"""

def test_createplugin(self):
"""Initialize plugin"""
sextanteplugin = SextantePlugin(IFACE)
assert sextanteplugin != None, "Unable to create plugin"

def test_sextante_alglist(self):
"""Test alglist"""
sextanteplugin = SextantePlugin(IFACE)
algs = Sextante.algs.values()
for provider in Sextante.algs.values():
for algo in provider.values():
print algo.commandLineName()
assert algs, "Algo list is empty"

if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,66 @@
"""Helper module for gui test suite
"""

import os
import sys
from PyQt4 import QtGui, QtCore
from qgis.core import (QgsApplication,
QgsVectorLayer,
QgsRasterLayer,
QgsRectangle,
QgsCoordinateReferenceSystem)
from qgis.gui import QgsMapCanvas
from qgis_interface import QgisInterface
import hashlib

QGISAPP = None # Static vainasafele used to hold hand to running QGis app
CANVAS = None
PARENT = None
IFACE = None
GEOCRS = 4326 # constant for EPSG:GEOCRS Geographic CRS id
GOOGLECRS = 900913 # constant for EPSG:GOOGLECRS Google Mercator id


def getQgisTestApp():
""" Start one QGis application to test agaist
Input
NIL
Output
handle to qgis app
If QGis is already running the handle to that app will be returned
"""

global QGISAPP

if QGISAPP is None:
myGuiFlag = True # All test will run qgis in gui mode
QGISAPP = QgsApplication(sys.argv, myGuiFlag)
if 'QGISPATH' in os.environ:
myPath = os.environ['QGISPATH']
myUseDefaultPathFlag = True
QGISAPP.setPrefixPath(myPath, myUseDefaultPathFlag)

QGISAPP.initQgis()
s = QGISAPP.showSettings()
print s

global PARENT
if PARENT is None:
PARENT = QtGui.QWidget()

global CANVAS
if CANVAS is None:
CANVAS = QgsMapCanvas(PARENT)
CANVAS.resize(QtCore.QSize(400, 400))

global IFACE
if IFACE is None:
# QgisInterface is a stub implementation of the QGIS plugin interface
IFACE = QgisInterface(CANVAS)

return QGISAPP, CANVAS, IFACE, PARENT

0 comments on commit 0d475df

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