Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 23, 2018
1 parent 0e928e8 commit 2c425c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def getParametersPanel(self, alg, parent):

def runAsBatch(self):
self.close()
dlg = BatchAlgorithmDialog(self.algorithm())
dlg = BatchAlgorithmDialog(self.algorithm(), parent=iface.mainWindow())
dlg.show()
dlg.exec_()

Expand Down
25 changes: 14 additions & 11 deletions python/plugins/processing/tests/GuiTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
class AlgorithmDialogTest(unittest.TestCase):

def testCreation(self):
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
a = AlgorithmDialog(alg)
self.assertEqual(a.mainWidget().alg, alg)

Expand All @@ -67,7 +67,7 @@ def setUpClass(cls):
ProcessingConfig.initialize()

def checkConstructWrapper(self, param, expected_wrapper_class):
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')

# algorithm dialog
dlg = AlgorithmDialog(alg)
Expand All @@ -77,6 +77,7 @@ def checkConstructWrapper(self, param, expected_wrapper_class):
self.assertEqual(wrapper.dialog, dlg)
self.assertIsNotNone(wrapper.widget)

alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
# batch dialog
dlg = BatchAlgorithmDialog(alg)
wrapper = WidgetWrapperFactory.create_wrapper_from_class(param, dlg)
Expand All @@ -85,6 +86,8 @@ def checkConstructWrapper(self, param, expected_wrapper_class):
self.assertEqual(wrapper.dialog, dlg)
self.assertIsNotNone(wrapper.widget)

alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')

# modeler dialog
model = QgsProcessingModelAlgorithm()
dlg = ModelerParametersDialog(alg, model)
Expand Down Expand Up @@ -138,7 +141,7 @@ def testSource(self):
self.assertTrue(layer.isValid())
QgsProject.instance().addMapLayer(layer)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterFeatureSource('test')
wrapper = FeatureSourceWidgetWrapper(param, dlg)
Expand Down Expand Up @@ -175,7 +178,7 @@ 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')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterRange(
name='test',
Expand Down Expand Up @@ -237,7 +240,7 @@ def testMapLayer(self):
def testDistance(self):
self.checkConstructWrapper(QgsProcessingParameterDistance('test'), DistanceWidgetWrapper)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterDistance('test')
wrapper = DistanceWidgetWrapper(param, dlg)
Expand Down Expand Up @@ -322,7 +325,7 @@ def testDistance(self):
def testMatrix(self):
self.checkConstructWrapper(QgsProcessingParameterMatrix('test'), FixedTableWidgetWrapper)

alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
dlg = AlgorithmDialog(alg)
param = QgsProcessingParameterMatrix('test', 'test', 2, True, ['x', 'y'], [['a', 'b'], ['c', 'd']])
wrapper = FixedTableWidgetWrapper(param, dlg)
Expand All @@ -346,7 +349,7 @@ def testBand(self):

def testFeatureSink(self):
param = QgsProcessingParameterFeatureSink('test')
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)

panel.setValue('memory:')
Expand Down Expand Up @@ -382,7 +385,7 @@ def testFeatureSink(self):

def testVectorDestination(self):
param = QgsProcessingParameterVectorDestination('test')
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)

panel.setValue('''ogr:dbname='/me/a.gpkg' table="d" (geom) sql=''')
Expand Down Expand Up @@ -412,7 +415,7 @@ def testVectorDestination(self):

def testRasterDestination(self):
param = QgsProcessingParameterRasterDestination('test')
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)

panel.setValue('/home/me/test.tif')
Expand All @@ -430,7 +433,7 @@ def testRasterDestination(self):

def testFolderDestination(self):
param = QgsProcessingParameterFolderDestination('test')
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)

panel.setValue('/home/me/test.tif')
Expand All @@ -444,7 +447,7 @@ def testFolderDestination(self):

def testFileDestination(self):
param = QgsProcessingParameterFileDestination('test')
alg = QgsApplication.processingRegistry().algorithmById('native:centroids')
alg = QgsApplication.processingRegistry().createAlgorithmById('native:centroids')
panel = DestinationSelectionPanel(param, alg)

panel.setValue('/home/me/test.tif')
Expand Down

0 comments on commit 2c425c7

Please sign in to comment.