2017-08-05 06:47:22 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
ParametersTest
|
|
|
|
---------------------
|
|
|
|
Date : August 2017
|
|
|
|
Copyright : (C) 2017 by Nyall Dawson
|
|
|
|
Email : nyall dot dawson 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__ = 'Nyall Dawson'
|
|
|
|
__date__ = 'August 2017'
|
|
|
|
__copyright__ = '(C) 2017, Nyall Dawson'
|
|
|
|
|
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
|
|
|
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
|
|
|
from qgis.testing import start_app, unittest
|
|
|
|
from qgis.core import QgsApplication
|
2017-10-16 17:35:55 +10:00
|
|
|
from qgis.analysis import QgsNativeAlgorithms
|
2017-08-05 06:47:22 +10:00
|
|
|
|
|
|
|
from processing.gui.AlgorithmDialog import AlgorithmDialog
|
2017-08-23 00:13:15 +10:00
|
|
|
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
|
|
|
|
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
|
|
|
|
from processing.gui.wrappers import *
|
2017-08-05 06:47:22 +10:00
|
|
|
|
|
|
|
start_app()
|
2017-10-16 17:35:55 +10:00
|
|
|
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
2017-08-05 06:47:22 +10:00
|
|
|
|
|
|
|
|
|
|
|
class AlgorithmDialogTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def testCreation(self):
|
|
|
|
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
|
|
|
|
a = AlgorithmDialog(alg)
|
2017-11-29 15:09:19 +10:00
|
|
|
self.assertEqual(a.mainWidget().alg, alg)
|
2017-08-05 06:47:22 +10:00
|
|
|
|
|
|
|
|
2017-08-23 00:13:15 +10:00
|
|
|
class WrappersTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def checkConstructWrapper(self, param, expected_wrapper_class):
|
|
|
|
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
|
|
|
|
|
|
|
|
# algorithm dialog
|
|
|
|
dlg = AlgorithmDialog(alg)
|
|
|
|
wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg)
|
|
|
|
self.assertIsNotNone(wrapper)
|
|
|
|
self.assertIsInstance(wrapper, expected_wrapper_class)
|
|
|
|
self.assertEqual(wrapper.dialog, dlg)
|
|
|
|
self.assertIsNotNone(wrapper.widget)
|
|
|
|
|
|
|
|
# batch dialog
|
|
|
|
dlg = BatchAlgorithmDialog(alg)
|
|
|
|
wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg)
|
|
|
|
self.assertIsNotNone(wrapper)
|
|
|
|
self.assertIsInstance(wrapper, expected_wrapper_class)
|
|
|
|
self.assertEqual(wrapper.dialog, dlg)
|
|
|
|
self.assertIsNotNone(wrapper.widget)
|
|
|
|
|
|
|
|
# modeler dialog
|
|
|
|
model = QgsProcessingModelAlgorithm()
|
|
|
|
dlg = ModelerParametersDialog(alg, model)
|
|
|
|
wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg)
|
|
|
|
self.assertIsNotNone(wrapper)
|
|
|
|
self.assertIsInstance(wrapper, expected_wrapper_class)
|
|
|
|
self.assertEqual(wrapper.dialog, dlg)
|
|
|
|
self.assertIsNotNone(wrapper.widget)
|
|
|
|
|
|
|
|
def testBoolean(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterBoolean('test'), BooleanWidgetWrapper)
|
|
|
|
|
|
|
|
def testCrs(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterCrs('test'), CrsWidgetWrapper)
|
|
|
|
|
|
|
|
def testExtent(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterExtent('test'), ExtentWidgetWrapper)
|
|
|
|
|
|
|
|
def testPoint(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterPoint('test'), PointWidgetWrapper)
|
|
|
|
|
|
|
|
def testFile(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterFile('test'), FileWidgetWrapper)
|
|
|
|
|
|
|
|
def testMultiInput(self):
|
2017-08-23 00:16:42 +10:00
|
|
|
self.checkConstructWrapper(QgsProcessingParameterMultipleLayers('test'), MultipleLayerWidgetWrapper)
|
2017-08-23 00:13:15 +10:00
|
|
|
|
|
|
|
def testRasterInput(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterRasterLayer('test'), RasterWidgetWrapper)
|
|
|
|
|
|
|
|
def testEnum(self):
|
2017-08-23 00:16:42 +10:00
|
|
|
self.checkConstructWrapper(QgsProcessingParameterEnum('test'), EnumWidgetWrapper)
|
2017-08-23 00:13:15 +10:00
|
|
|
|
|
|
|
def testString(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterString('test'), StringWidgetWrapper)
|
|
|
|
|
|
|
|
def testExpression(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterExpression('test'), ExpressionWidgetWrapper)
|
|
|
|
|
|
|
|
def testVector(self):
|
2017-08-23 00:16:42 +10:00
|
|
|
self.checkConstructWrapper(QgsProcessingParameterVectorLayer('test'), VectorLayerWidgetWrapper)
|
2017-08-23 00:13:15 +10:00
|
|
|
|
|
|
|
def testField(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterField('test'), TableFieldWidgetWrapper)
|
|
|
|
|
|
|
|
def testSource(self):
|
2017-08-23 00:16:42 +10:00
|
|
|
self.checkConstructWrapper(QgsProcessingParameterFeatureSource('test'), FeatureSourceWidgetWrapper)
|
2017-08-23 00:13:15 +10:00
|
|
|
|
|
|
|
def testSource(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterBand('test'), BandWidgetWrapper)
|
|
|
|
|
|
|
|
def testMapLayer(self):
|
|
|
|
self.checkConstructWrapper(QgsProcessingParameterMapLayer('test'), MapLayerWidgetWrapper)
|
|
|
|
|
|
|
|
|
2017-08-05 06:47:22 +10:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|