Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 2, 2018
1 parent 2cc9bc8 commit f43adf7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/NumberInputPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def getLayerFromValue(self, value):
value, ok = value.source.valueAsString(context.expressionContext())
if isinstance(value, str):
value = QgsProcessingUtils.mapLayerFromString(value, context)
if value is None:
if value is None or not isinstance(value, QgsMapLayer):
return None

# need to return layer with ownership - otherwise layer may be deleted when context
Expand Down
17 changes: 14 additions & 3 deletions python/plugins/processing/tests/GuiTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from qgis.core import (QgsApplication,
QgsCoordinateReferenceSystem,
QgsProcessingParameterMatrix,
QgsVectorLayer)
QgsVectorLayer,
QgsProject)
from qgis.analysis import QgsNativeAlgorithms

from processing.gui.AlgorithmDialog import AlgorithmDialog
Expand Down Expand Up @@ -152,11 +153,21 @@ def testDistance(self):
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)
vl2 = QgsVectorLayer("Polygon?crs=epsg:4326&field=pk:int", "vl", "memory")
widget.setUnitParameterValue(vl2)
self.assertEqual(widget.label.text(), 'degrees')
self.assertTrue(widget.warning_label.isVisible())

# unresolvable values
widget.setUnitParameterValue(vl.id())
self.assertEqual(widget.label.text(), '<unknown>')
self.assertFalse(widget.warning_label.isVisible())
# resolvable text value
QgsProject.instance().addMapLayer(vl)
widget.setUnitParameterValue(vl.id())
self.assertEqual(widget.label.text(), 'meters')
self.assertFalse(widget.warning_label.isVisible())

widget.deleteLater()

def testMatrix(self):
Expand Down

0 comments on commit f43adf7

Please sign in to comment.