From 8ce3e8b9ac26ec4afcbc99ec176cb6d324d2e00b Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 23 Nov 2018 10:16:11 +1000 Subject: [PATCH] Fix unit test (cherry picked from commit c31a690ea01052e8fdf2ecc7eb152d936f9196c7) --- .../plugins/processing/gui/AlgorithmDialog.py | 2 +- python/plugins/processing/tests/GuiTest.py | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/python/plugins/processing/gui/AlgorithmDialog.py b/python/plugins/processing/gui/AlgorithmDialog.py index 79daf445279b..4066a8615bb8 100644 --- a/python/plugins/processing/gui/AlgorithmDialog.py +++ b/python/plugins/processing/gui/AlgorithmDialog.py @@ -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_() diff --git a/python/plugins/processing/tests/GuiTest.py b/python/plugins/processing/tests/GuiTest.py index 62b8370ceb84..1dbb8fdceb39 100644 --- a/python/plugins/processing/tests/GuiTest.py +++ b/python/plugins/processing/tests/GuiTest.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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', @@ -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) @@ -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) @@ -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:') @@ -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=''') @@ -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') @@ -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') @@ -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')