Skip to content
Permalink
Browse files

Add basic unit tests for constructing processing widget wrappers

  • Loading branch information
nyalldawson committed Aug 22, 2017
1 parent 9882e4f commit c119c286eb06d674cfcbb31758705880d9d4199d
@@ -61,10 +61,14 @@ def __init__(self, dialog, param):

self.btnSelect.clicked.connect(self.selectExtent)

canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
self.tool.rectangleCreated.connect(self.updateExtent)
if iface is not None:
canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
self.tool.rectangleCreated.connect(self.updateExtent)
else:
self.prevMapTool = None
self.tool = None

if param.defaultValue() is not None:
context = createContext()
@@ -49,11 +49,15 @@ def __init__(self, dialog, default=None):

self.dialog = dialog

canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
if iface is not None:
canvas = iface.mapCanvas()
self.prevMapTool = canvas.mapTool()

self.tool = PointMapTool(canvas)
self.tool.canvasClicked.connect(self.updatePoint)
self.tool = PointMapTool(canvas)
self.tool.canvasClicked.connect(self.updatePoint)
else:
self.prevMapTool = None
self.tool = None

if default:
tokens = str(default).split(',')
@@ -29,6 +29,9 @@
from qgis.core import QgsApplication

from processing.gui.AlgorithmDialog import AlgorithmDialog
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
from processing.gui.wrappers import *

start_app()

@@ -41,5 +44,81 @@ def testCreation(self):
self.assertEqual(a.mainWidget.alg, alg)


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):
self.checkConstructWrapper(QgsProcessingParameterMultipleLayers('test'), MultipleInputWidgetWrapper)

def testRasterInput(self):
self.checkConstructWrapper(QgsProcessingParameterRasterLayer('test'), RasterWidgetWrapper)

def testEnum(self):
self.checkConstructWrapper(QgsProcessingParameterEnum('test'), SelectionWidgetWrapper)

def testString(self):
self.checkConstructWrapper(QgsProcessingParameterString('test'), StringWidgetWrapper)

def testExpression(self):
self.checkConstructWrapper(QgsProcessingParameterExpression('test'), ExpressionWidgetWrapper)

def testVector(self):
self.checkConstructWrapper(QgsProcessingParameterVectorLayer('test'), TableWidgetWrapper)

def testField(self):
self.checkConstructWrapper(QgsProcessingParameterField('test'), TableFieldWidgetWrapper)

def testSource(self):
self.checkConstructWrapper(QgsProcessingParameterFeatureSource('test'), VectorWidgetWrapper)

def testSource(self):
self.checkConstructWrapper(QgsProcessingParameterBand('test'), BandWidgetWrapper)

def testMapLayer(self):
self.checkConstructWrapper(QgsProcessingParameterMapLayer('test'), MapLayerWidgetWrapper)


if __name__ == '__main__':
unittest.main()

0 comments on commit c119c28

Please sign in to comment.
You can’t perform that action at this time.