Skip to content
Permalink
Browse files

[processing] Unit tests for distance param widget wrapper

  • Loading branch information
nyalldawson committed Apr 20, 2018
1 parent 91c1277 commit d87f75aa98b24d04f72ce7b9df869a3a5ae2d877
Showing with 38 additions and 1 deletion.
  1. +38 −1 python/plugins/processing/tests/GuiTest.py
@@ -26,7 +26,9 @@
__revision__ = '$Format:%H$'

from qgis.testing import start_app, unittest
from qgis.core import QgsApplication
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
QgsVectorLayer)
from qgis.analysis import QgsNativeAlgorithms

from processing.gui.AlgorithmDialog import AlgorithmDialog
@@ -121,6 +123,41 @@ def testMapLayer(self):
def testDistance(self):
self.checkConstructWrapper(QgsProcessingParameterDistance('test'), DistanceWidgetWrapper)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterDistance('test')
wrapper = DistanceWidgetWrapper(param, dlg)
widget = wrapper.createWidget()

# test units
widget.show()

# crs values
widget.setUnitParameterValue('EPSG:3111')
self.assertEqual(widget.label.text(), 'meters')
self.assertFalse(widget.warning_label.isVisible())
widget.setUnitParameterValue('EPSG:4326')
self.assertEqual(widget.label.text(), 'degrees')
self.assertTrue(widget.warning_label.isVisible())
widget.setUnitParameterValue(QgsCoordinateReferenceSystem('EPSG:3111'))
self.assertEqual(widget.label.text(), 'meters')
self.assertFalse(widget.warning_label.isVisible())
widget.setUnitParameterValue(QgsCoordinateReferenceSystem('EPSG:4326'))
self.assertEqual(widget.label.text(), 'degrees')
self.assertTrue(widget.warning_label.isVisible())

# layer values
vl = QgsVectorLayer("Polygon?crs=epsg:3111&field=pk:int", "vl", "memory")
widget.setUnitParameterValue(vl)
self.assertEqual(widget.label.text(), 'meters')
self.assertFalse(widget.warning_label.isVisible())
vl = QgsVectorLayer("Polygon?crs=epsg:4326&field=pk:int", "vl", "memory")
widget.setUnitParameterValue(vl)
self.assertEqual(widget.label.text(), 'degrees')
self.assertTrue(widget.warning_label.isVisible())

widget.deleteLater()

def testNumber(self):
self.checkConstructWrapper(QgsProcessingParameterNumber('test'), NumberWidgetWrapper)

0 comments on commit d87f75a

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