2013-04-13 11:04:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2013-08-12 20:44:27 +02:00
|
|
|
ProcessingToolsTest.py
|
2013-04-13 11:04:22 +02:00
|
|
|
---------------------
|
|
|
|
Date : April 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__ = 'April 2013'
|
|
|
|
__copyright__ = '(C) 2013, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-04-13 11:04:22 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-04-13 11:04:22 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
import unittest
|
2013-10-01 20:52:22 +03:00
|
|
|
|
|
|
|
import processing
|
2013-08-12 20:44:27 +02:00
|
|
|
from processing.core import Processing
|
|
|
|
from processing.tools.vector import values
|
2013-09-17 12:33:57 +02:00
|
|
|
from processing.tools.dataobjects import *
|
2013-04-09 23:11:11 +02:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
from processing.tests.TestData import points, points2, polygons, polygons2, \
|
|
|
|
lines, union, table, polygonsGeoJson, raster
|
|
|
|
|
|
|
|
|
2013-08-12 20:44:27 +02:00
|
|
|
class ProcessingToolsTest(unittest.TestCase):
|
2013-10-01 20:52:22 +03:00
|
|
|
'''Tests the method imported when doing an "import processing", and
|
|
|
|
also in processing.tools. They are mostly convenience tools.
|
|
|
|
'''
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_getobject(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
layer = processing.getObject(points())
|
2013-04-15 07:16:20 +02:00
|
|
|
self.assertIsNotNone(layer)
|
2013-10-01 20:52:22 +03:00
|
|
|
layer = processing.getObject('points')
|
2013-04-09 23:11:11 +02:00
|
|
|
self.assertIsNotNone(layer)
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_runandload(self):
|
2013-10-01 20:52:22 +03:00
|
|
|
processing.runandload('qgis:countpointsinpolygon', polygons(),
|
|
|
|
points(), 'NUMPOINTS', None)
|
|
|
|
layer = getObjectFromName('Result')
|
2013-04-15 07:16:20 +02:00
|
|
|
self.assertIsNotNone(layer)
|
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_featuresWithoutSelection(self):
|
2013-09-12 13:19:00 +02:00
|
|
|
layer = processing.getObject(points())
|
|
|
|
features = processing.features(layer)
|
2013-04-15 07:16:20 +02:00
|
|
|
self.assertEqual(12, len(features))
|
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_featuresWithSelection(self):
|
2013-09-12 13:19:00 +02:00
|
|
|
layer = processing.getObject(points())
|
2013-04-09 23:11:11 +02:00
|
|
|
feature = layer.getFeatures().next()
|
|
|
|
selected = [feature.id()]
|
|
|
|
layer.setSelectedFeatures(selected)
|
2013-09-12 13:19:00 +02:00
|
|
|
features = processing.features(layer)
|
2013-04-09 23:11:11 +02:00
|
|
|
self.assertEqual(1, len(features))
|
|
|
|
layer.setSelectedFeatures([])
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_attributeValues(self):
|
2013-09-12 13:19:00 +02:00
|
|
|
layer = processing.getObject(points())
|
2013-10-01 20:52:22 +03:00
|
|
|
attributeValues = values(layer, 'ID')
|
2013-04-09 23:11:11 +02:00
|
|
|
i = 1
|
2013-04-10 15:03:17 +02:00
|
|
|
for value in attributeValues['ID']:
|
2013-04-09 23:11:11 +02:00
|
|
|
self.assertEqual(int(i), int(value))
|
2013-10-01 20:52:22 +03:00
|
|
|
i += 1
|
|
|
|
self.assertEquals(13, i)
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def test_extent(self):
|
|
|
|
pass
|
2013-04-15 07:16:20 +02:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
|
|
|
|
def suite():
|
2013-08-12 20:44:27 +02:00
|
|
|
suite = unittest.makeSuite(ProcessingToolsTest, 'test')
|
2013-04-09 23:11:11 +02:00
|
|
|
return suite
|
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-04-09 23:11:11 +02:00
|
|
|
def runtests():
|
|
|
|
result = unittest.TestResult()
|
|
|
|
testsuite = suite()
|
|
|
|
testsuite.run(result)
|
|
|
|
return result
|