Skip to content
Permalink
Browse files

added test for RangePanel widget

  • Loading branch information
luipir authored and nyalldawson committed Sep 7, 2018
1 parent bc8a460 commit 7944f6704bcecc418ae2d5f1c53bebcaf25c76c7
Showing with 61 additions and 0 deletions.
  1. +61 −0 python/plugins/processing/tests/GuiTest.py
@@ -35,6 +35,7 @@
QgsProcessingParameterFolderDestination,
QgsProcessingParameterVectorDestination,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterRange,
QgsVectorLayer,
QgsProject)
from qgis.analysis import QgsNativeAlgorithms
@@ -170,6 +171,66 @@ def testSource(self):
value = wrapper.value()
self.assertEqual(value, '/home/my_layer.shp')

def testRange(self):
# minimal test to check if wrapper generate GUI for each processign context
self.checkConstructWrapper(QgsProcessingParameterRange('test'), RangeWidgetWrapper)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterRange(
name='test',
description='test',
type=QgsProcessingParameterNumber.Double,
defaultValue="0.0,100.0")

wrapper = RangeWidgetWrapper(param, dlg)
widget = wrapper.createWidget()

# range values check

# check intial value
self.assertEqual(widget.getValue(), '0.0,100.0')
# check set/get
widget.setValue("100.0,200.0")
self.assertEqual(widget.getValue(), '100.0,200.0')
# check that min/max are mutually adapted
widget.setValue("200.0,100.0")
self.assertEqual(widget.getValue(), '100.0,100.0')
widget.spnMax.setValue(50)
self.assertEqual(widget.getValue(), '50.0,50.0')
widget.spnMin.setValue(100)
self.assertEqual(widget.getValue(), '100.0,100.0')

# check for integers
param = QgsProcessingParameterRange(
name='test',
description='test',
type=QgsProcessingParameterNumber.Integer,
defaultValue="0.1,100.1")

wrapper = RangeWidgetWrapper(param, dlg)
widget = wrapper.createWidget()

# range values check

# check intial value
self.assertEqual(widget.getValue(), '0.0,100.0')
# check rounding
widget.setValue("100.1,200.1")
self.assertEqual(widget.getValue(), '100.0,200.0')
widget.setValue("100.6,200.6")
self.assertEqual(widget.getValue(), '101.0,201.0')
# check set/get
widget.setValue("100.1,200.1")
self.assertEqual(widget.getValue(), '100.0,200.0')
# check that min/max are mutually adapted
widget.setValue("200.1,100.1")
self.assertEqual(widget.getValue(), '100.0,100.0')
widget.spnMax.setValue(50.1)
self.assertEqual(widget.getValue(), '50.0,50.0')
widget.spnMin.setValue(100.1)
self.assertEqual(widget.getValue(), '100.0,100.0')

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

0 comments on commit 7944f67

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