2013-04-13 11:04:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
GeoAlgorithmTest.py
|
|
|
|
---------------------
|
|
|
|
Date : March 2013
|
|
|
|
Copyright : (C) 2013 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* 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__ = 'Victor Olaya'
|
|
|
|
__date__ = 'March 2013'
|
|
|
|
__copyright__ = '(C) 2013, Victor Olaya'
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
import processing
|
2013-04-09 23:11:11 +02:00
|
|
|
import unittest
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.tests.TestData import points, points2, polygons, polygons2, lines, union,\
|
2013-04-09 23:11:11 +02:00
|
|
|
table, polygonsGeoJson, raster
|
2013-09-12 13:19:00 +02:00
|
|
|
from processing.tools import dataobjects
|
|
|
|
from processing.tools.system import *
|
2013-03-01 15:54:01 +01:00
|
|
|
|
2013-04-15 07:16:20 +02:00
|
|
|
class GeoAlgorithmTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def testWrongformat(self):
|
2013-09-12 13:19:00 +02:00
|
|
|
outputs=processing.runalg("qgis:countpointsinpolygon",polygons(),points(),"NUMPOINTS",getTempFilename("wrongext"))
|
2013-04-12 12:30:59 +02:00
|
|
|
output=outputs['OUTPUT']
|
2013-04-15 07:16:20 +02:00
|
|
|
self.assertTrue(output.endswith('shp'))
|
2013-09-12 13:19:00 +02:00
|
|
|
layer=dataobjects.getObjectFromUri(output, True)
|
2013-04-12 12:30:59 +02:00
|
|
|
fields=layer.pendingFields()
|
|
|
|
expectednames=['ID','POLY_NUM_A','POLY_ST_A','NUMPOINTS']
|
|
|
|
expectedtypes=['Integer','Real','String','Real']
|
|
|
|
names=[str(f.name()) for f in fields]
|
|
|
|
types=[str(f.typeName()) for f in fields]
|
|
|
|
self.assertEqual(expectednames, names)
|
|
|
|
self.assertEqual(expectedtypes, types)
|
2013-09-12 13:19:00 +02:00
|
|
|
features=processing.features(layer)
|
2013-04-12 12:30:59 +02:00
|
|
|
self.assertEqual(2, len(features))
|
|
|
|
feature=features.next()
|
|
|
|
attrs=feature.attributes()
|
2013-06-09 16:04:44 +02:00
|
|
|
expectedvalues=["1","1.1","string a","6.0"]
|
|
|
|
values=[str(attr) for attr in attrs]
|
2013-04-12 12:30:59 +02:00
|
|
|
self.assertEqual(expectedvalues, values)
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-03-26 14:15:12 +01:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def suite():
|
|
|
|
suite = unittest.makeSuite(GeoAlgorithmTest, 'test')
|
|
|
|
return suite
|
2013-03-26 14:15:12 +01:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def runtests():
|
|
|
|
result = unittest.TestResult()
|
|
|
|
testsuite = suite()
|
|
|
|
testsuite.run(result)
|
|
|
|
return result
|