|
28 | 28 | sys.path.append('/usr/share/qgis/python/plugins')
|
29 | 29 |
|
30 | 30 | from qgis.gui import QgsMapCanvas
|
| 31 | +from qgis.core import * |
31 | 32 | from qgis_interface import QgisInterface
|
32 | 33 | from PyQt4.QtGui import QWidget
|
33 | 34 | from utilities_test import getQgisTestApp
|
34 | 35 | #from gui.is_plugin import ISPlugin
|
35 |
| -from sextante import SextantePlugin |
| 36 | +from sextante.SextantePlugin import SextantePlugin |
36 | 37 | from sextante.core.Sextante import Sextante
|
| 38 | +from sextante.parameters.ParameterRaster import ParameterRaster |
| 39 | +from sextante.parameters.ParameterVector import ParameterVector |
| 40 | +from sextante.parameters.ParameterNumber import ParameterNumber |
| 41 | +from sextante.outputs.OutputRaster import OutputRaster |
| 42 | +from sextante.outputs.OutputVector import OutputVector |
37 | 43 | QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
|
38 | 44 |
|
| 45 | +class DataProviderStub: |
| 46 | + def __init__(self, uri): |
| 47 | + self.dataSourceUri = lambda: uri |
39 | 48 |
|
40 | 49 | class SextantePluginTest(unittest.TestCase):
|
41 | 50 | """Test suite for Sextante QGis plugin"""
|
42 |
| - |
43 |
| - def test_createplugin(self): |
| 51 | + def gen_test_parameters(self, alg): |
| 52 | + for p in alg.parameters: |
| 53 | + if isinstance(p, ParameterRaster): |
| 54 | + l = QgsRasterLayer('.data/raster', "test raster") |
| 55 | + l.dataProvider = lambda: DataProviderStub('data/raster') |
| 56 | + yield l |
| 57 | + elif isinstance(p, ParameterVector): |
| 58 | + l = QgsVectorLayer('.data/vector', "test vector") |
| 59 | + l.dataProvider = lambda: DataProviderStub('data/vector') |
| 60 | + yield l |
| 61 | + elif isinstance(p, ParameterNumber): |
| 62 | + yield p.max |
| 63 | + else: |
| 64 | + yield |
| 65 | + i = 0; |
| 66 | + for o in alg.outputs: |
| 67 | + if o.hidden: |
| 68 | + continue; |
| 69 | + i = i + 1 |
| 70 | + if isinstance(o, OutputRaster): |
| 71 | + yield 'output%i.tif' % i |
| 72 | + elif isinstance(o, OutputVector): |
| 73 | + yield 'output%i.shp' % i |
| 74 | + else: |
| 75 | + yield |
| 76 | + |
| 77 | + def test_0createplugin(self): |
44 | 78 | """Initialize plugin"""
|
45 |
| - sextanteplugin = SextantePlugin(IFACE) |
46 |
| - assert sextanteplugin != None, "Unable to create plugin" |
| 79 | + self.sextanteplugin = SextantePlugin(IFACE) |
| 80 | + self.assertIsNotNone(self.sextanteplugin) |
47 | 81 |
|
48 |
| - def test_sextante_alglist(self): |
| 82 | + def test_1sextante_alglist(self): |
49 | 83 | """Test alglist"""
|
50 |
| - sextanteplugin = SextantePlugin(IFACE) |
51 |
| - algs = Sextante.algs.values() |
52 |
| - for provider in Sextante.algs.values(): |
53 |
| - for algo in provider.values(): |
54 |
| - print algo.commandLineName() |
55 |
| - assert algs, "Algo list is empty" |
| 84 | + self.sextanteplugin = SextantePlugin(IFACE) |
| 85 | + self.providerToAlgs = Sextante.algs |
| 86 | + self.assertTrue(self.providerToAlgs, "Alg list") |
| 87 | + |
| 88 | + def test_runalg(self): |
| 89 | + self.sextanteplugin = SextantePlugin(IFACE) |
| 90 | + self.providerToAlgs = Sextante.algs |
| 91 | + for provider, algs in self.providerToAlgs.items(): |
| 92 | + if not algs.items(): |
| 93 | + print "WARINING: %s seems to provide no algs!" % provider |
| 94 | + continue |
| 95 | + algId, alg = algs.items()[-1] |
| 96 | + args = list(self.gen_test_parameters(alg)) |
| 97 | + print "Alg: ", algId |
| 98 | + print alg.parameters, ' => ', args |
| 99 | + result = Sextante.runalg(algId, *args) |
| 100 | + self.assertIsNotNone(result, "Running directly %s" % algId) |
| 101 | + print algId, " ok." |
56 | 102 |
|
57 | 103 | if __name__ == '__main__':
|
58 | 104 | unittest.main()
|
0 commit comments