QGIS/python/plugins/processing/tests/ProcessingToolsTest.py

93 lines
3.0 KiB
Python
Raw Normal View History

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-04-13 11:04:22 +02:00
# This will get replaced with a git SHA1 when you do a git archive
2013-04-13 11:04:22 +02:00
__revision__ = '$Format:%H$'
2013-04-09 23:11:11 +02:00
import unittest
import processing
2013-08-12 20:44:27 +02:00
from processing.core import Processing
from processing.tools.vector import values
from processing.tools.dataobjects import *
2013-04-09 23:11:11 +02: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):
'''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):
layer = processing.getObject(points())
2013-04-15 07:16:20 +02:00
self.assertIsNotNone(layer)
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):
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):
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):
layer = processing.getObject(points())
2013-04-09 23:11:11 +02:00
feature = layer.getFeatures().next()
selected = [feature.id()]
layer.setSelectedFeatures(selected)
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):
layer = processing.getObject(points())
attributeValues = values(layer, 'ID')
2013-04-09 23:11:11 +02:00
i = 1
for value in attributeValues['ID']:
2013-04-09 23:11:11 +02:00
self.assertEqual(int(i), int(value))
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-04-09 23:11:11 +02:00
def runtests():
result = unittest.TestResult()
testsuite = suite()
testsuite.run(result)
return result