11 changes: 8 additions & 3 deletions python/plugins/sextante/tests/ParametersTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ def testParameterExtent(self):
assert param.description == param2.description
assert param.name == param2.name

def suite():
suite = unittest.makeSuite(ParametersTest, 'test')
return suite


if __name__ == '__main__':
unittest.main()
def runtests():
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result
2 changes: 1 addition & 1 deletion python/plugins/sextante/tests/RunAlgTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parametrize(testcase_klass, useTempFiles):

class RunAlgTest(ParametrizedTestCase):
'''This test takes a reduced set of algorithms and executes them in different ways, changing
parameters such as whether to use thread or not, the output file format, etc.
parameters such as whether to use temp outputs, the output file format, etc.
Basically, it uses some algorithms to test other parts of SEXTANTE, not the algorithms themselves'''

def getOutputFile(self):
Expand Down
81 changes: 81 additions & 0 deletions python/plugins/sextante/tests/SagaTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import sextante
import unittest
from sextante.tests.TestData import points, points2, polygons, polygons2, lines, union,\
table, polygonsGeoJson
from sextante.core.QGisLayers import QGisLayers
from sextante.core.SextanteUtils import SextanteUtils

class SagaTest(unittest.TestCase):
'''tests for saga algorithms'''


'''the following tests are not meant to test the algorithms themselves,
but the algorithm provider, testing things such as the file conversion,
the selection awareness of SAGA process, etc'''

def test_SagaVvectorAlgorithmWithSelection(self):
layer = sextante.getobject(polygons2());
feature = layer.getFeatures().next()
selected = [feature.id()]
layer.setSelectedFeatures(selected)
outputs=sextante.runalg("saga:polygoncentroids",polygons2(),True,None)
output=outputs['CENTROIDS']
layer=QGisLayers.getObjectFromUri(output, True)
fields=layer.pendingFields()
expectednames=['ID','POLY_NUM_B','POLY_ST_B']
expectedtypes=['Real','Real','String']
names=[str(f.name()) for f in fields]
types=[str(f.typeName()) for f in fields]
self.assertEqual(expectednames, names)
self.assertEqual(expectedtypes, types)
features=sextante.getfeatures(layer)
self.assertEqual(1, len(features))
feature=features.next()
attrs=feature.attributes()
expectedvalues=["2","1","string a"]
values=[str(attr.toString()) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POINT(270820.58189697 4458968.73298999)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

def test_SagaVectorAlgorithWithUnsupportedInputAndOutputFormat(self):
'''this tests both the exporting to shp and then the format change in the output layer'''
layer = sextante.getobject(polygonsGeoJson());
feature = layer.getFeatures().next()
selected = [feature.id()]
layer.setSelectedFeatures(selected)
outputs=sextante.runalg("saga:polygoncentroids",polygonsGeoJson(),True, SextanteUtils.getTempFilename("geojson"))
output=outputs['CENTROIDS']
layer=QGisLayers.getObjectFromUri(output, True)
fields=layer.pendingFields()
expectednames=['ID','POLY_NUM_A','POLY_ST_A']
expectedtypes=['Real','Real','String']
names=[str(f.name()) for f in fields]
types=[str(f.typeName()) for f in fields]
self.assertEqual(expectednames, names)
self.assertEqual(expectedtypes, types)
features=sextante.getfeatures(layer)
self.assertEqual(1, len(features))
feature=features.next()
attrs=feature.attributes()
expectedvalues=["0","1.1","string a"]
values=[str(attr.toString()) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POINT(270787.49991451 4458955.46775295)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))







def suite():
suite = unittest.makeSuite(SagaTest, 'test')
return suite

def runtests():
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result
6 changes: 6 additions & 0 deletions python/plugins/sextante/tests/ScriptTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sextante.core.QGisLayers import QGisLayers

class ScriptTest(unittest.TestCase):
'''tests that use scripts'''

def test_scriptcreatetilingfromvectorlayer(self):
outputs=sextante.runalg("script:createtilingfromvectorlayer",union(),10,None)
Expand Down Expand Up @@ -47,6 +48,11 @@ def test_scripthexgridfromlayerbounds(self):
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270771.39533669 4458907.27146471,270768.50858535 4458902.27146471,270762.73508265 4458902.27146471,270759.84833131 4458907.27146471,270762.73508265 4458912.27146471,270768.50858535 4458912.27146471,270771.39533669 4458907.27146471))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

def test_scriptascriptthatreturnsanumber(self):
outputs=sextante.runalg("script:ascriptthatreturnsanumber")
output=outputs['number']
self.assertTrue(10, output.value)

def suite():
suite = unittest.makeSuite(ScriptTest, 'test')
Expand Down
4 changes: 4 additions & 0 deletions python/plugins/sextante/tests/TestData.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def polygons():
def polygons2():
return os.path.join(dataFolder, "polygons2.shp")

def polygonsGeoJson():
return os.path.join(dataFolder, "polygons.geojson")

def union():
return os.path.join(dataFolder, "union.shp")

Expand All @@ -33,6 +36,7 @@ def loadTestData():
QGisLayers.load(points2(), "points2");
QGisLayers.load(polygons(), "polygons");
QGisLayers.load(polygons2(), "polygons2");
QGisLayers.load(polygonsGeoJson(), "polygonsGeoJson");
QGisLayers.load(lines(), "lines");
QGisLayers.load(raster(), "raster");
QGisLayers.load(table(), "table");
Expand Down
10 changes: 10 additions & 0 deletions python/plugins/sextante/tests/data/polygons.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "FeatureCollection",

"features": [
{ "type": "Feature", "properties": { "ID": 1, "POLY_NUM_A": 1.1, "POLY_ST_A": "string a" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 270771.6333011096, 4458992.3534930153 ], [ 270791.33997533983, 4458993.4795886856 ], [ 270799.03496242024, 4458993.1042234618 ], [ 270799.03496242024, 4458993.1042234618 ], [ 270815.36334963952, 4458986.9106972748 ], [ 270818.55395403871, 4458973.9605970662 ], [ 270798.42294526967, 4458914.6266167583 ], [ 270780.81854857568, 4458914.2198344888 ], [ 270759.84833130869, 4458922.0961403074 ], [ 270766.19050536986, 4458980.3418058651 ], [ 270771.6333011096, 4458992.3534930153 ] ] ] } }
,
{ "type": "Feature", "properties": { "ID": 2, "POLY_NUM_A": 2.2, "POLY_ST_A": "string b" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 270813.94335145224, 4458930.9869043007 ], [ 270826.51803935075, 4458988.1455448866 ], [ 270867.09612425708, 4458987.3911639042 ], [ 270870.43581757887, 4458937.3681130987 ], [ 270867.43289579143, 4458911.8432779051 ], [ 270834.58843874105, 4458902.2714647073 ], [ 270813.19262100535, 4458908.0896256706 ], [ 270813.63333506504, 4458913.927794693 ], [ 270813.94335145224, 4458930.9869043007 ] ] ] } }

]
}
16 changes: 0 additions & 16 deletions python/plugins/sextante/tests/runtests.sh

This file was deleted.