Skip to content


Parameter Dialog tests -- output check missing
Browse files Browse the repository at this point in the history
git-svn-id: 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information committed Jul 8, 2012
1 parent 6d01c98 commit 9fbfd48
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions src/sextante/tests/
Expand Up @@ -28,6 +28,7 @@

import itertools
import time
from qgis.gui import QgsMapCanvas
from qgis.core import *
from qgis_interface import QgisInterface
Expand All @@ -36,6 +37,7 @@
#from gui.is_plugin import ISPlugin
from sextante.SextantePlugin import SextantePlugin
from sextante.core.Sextante import Sextante
from sextante.gui.ParametersDialog import ParametersDialog
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterNumber import ParameterNumber
Expand Down Expand Up @@ -71,36 +73,43 @@ def test_sextante_alglist(self):
self.assertTrue(self.providerToAlgs, "Alg list")

class SextanteProviderTestCase(unittest.TestCase):
def __init__(self, algId, alg, threaded):
def __init__(self, algId, alg, threaded, dialog = "none"):
self.algId = algId
self.alg = alg
self.threaded = threaded
self.msg = "ALG %s (%s)" % (self.algId, { True: "threaded" , False : "unthreaded"}[threaded])
unittest.TestCase.__init__(self, "test_runalg")
self.msg = "ALG %s (%s %s)" % (self.algId, { True: "threaded" , False : "unthreaded"}[threaded], dialog)
unittest.TestCase.__init__(self, "runalg_%s" % dialog)

def gen_test_parameters(self, alg):
def gen_test_parameters(self, alg, doSet = False):
b = False
for p in alg.parameters:
if isinstance(p, ParameterRaster):
l = QgsRasterLayer('data/raster', "test raster")
l.dataProvider = lambda: DataProviderStub('data/raster')
if doSet: p.setValue(l)
yield l
elif isinstance(p, ParameterVector):
l = QgsVectorLayer('data/vector', "test vector")
l.dataProvider = lambda: DataProviderStub('data/vector')
if doSet: p.setValue(l)
yield l
elif isinstance(p, ParameterNumber):
n = 42
if p.max:
yield p.max
n = p.max
elif p.min:
yield p.min
yield 42
n = p.min
if doSet: p.setValue(n)
yield n
elif isinstance(p, ParameterString):
yield "Test string"
s = "Test string"
if doSet: p.setValue(s)
yield s
elif isinstance(p, ParameterBoolean):
b = not b
if doSet: p.setValue(b)
yield b
if doSet: p.setValue(None)
i = 0;
for o in alg.outputs:
Expand All @@ -109,18 +118,28 @@ def gen_test_parameters(self, alg):
i = i + 1
outbasename = self.msg.replace('/', '-')
if isinstance(o, OutputRaster):
yield 'outputs/%s - %i.tif' % (outbasename, i)
fn = 'outputs/%s - %i.tif' % (outbasename, i)
if doSet: o.setValue(fn)
yield fn
elif isinstance(o, OutputVector):
yield 'outputs/%s - %i.shp' % (outbasename, i)
fn = 'outputs/%s - %i.shp' % (outbasename, i)
if doSet: o.setValue(fn)
yield fn
if doSet: o.setValue(None)
def test_runalg(self):

def setUp(self):
SextanteConfig.setSettingValue(SextanteConfig.USE_THREADS, self.threaded)
args = list(self.gen_test_parameters(self.alg))
print bcolors.INFO, self.msg, bcolors.ENDC, "Parameters: ", self.alg.parameters, ' => ', args, bcolors.WARNING,
result = Sextante.runalg(self.algId, *args)
self.args = list(self.gen_test_parameters(self.alg, True))
print bcolors.INFO, self.msg, bcolors.ENDC,
print "Parameters: ", self.alg.parameters,
print "Outputs: ", [out for out in self.alg.outputs if not out.hidden],
print ' => ', self.args, bcolors.WARNING,

def runalg_none(self):
result = Sextante.runalg(self.algId, *self.args)
print bcolors.ENDC
self.assertIsNotNone(result, self.msg)
if not result:
Expand All @@ -129,6 +148,21 @@ def test_runalg(self):
if isinstance(p, str):
self.assertTrue(os.path.exists(p), "Output %s exists" % p)

def runalg_parameters(self):
dlg = self.alg.getCustomParametersDialog()
if not dlg:
dlg = ParametersDialog(self.alg)
# hack to handle that hacky code...
dlg.ui.setParamValues = lambda: True
while (not dlg.executed):

def tearDown(self):
print bcolors.ENDC

def algSuite():
s = unittest.TestSuite()
for provider, algs in Sextante.algs.items():
Expand All @@ -139,6 +173,8 @@ def algSuite():
algId, alg = algs.items()[-1]
s.addTest(SextanteProviderTestCase(algId, alg, True))
s.addTest(SextanteProviderTestCase(algId, alg, False))
s.addTest(SextanteProviderTestCase(algId, alg, True, "parameters"))
s.addTest(SextanteProviderTestCase(algId, alg, False, "parameters"))
return s

if __name__ == '__main__':
Expand Down

0 comments on commit 9fbfd48

Please sign in to comment.