Skip to content
Permalink
Browse files
Test that dependent plugins are located after their dependencies in m…
…PythonUtils->pluginList(), which will be the order used to load Python plugins to QGIS
  • Loading branch information
gacarrillor authored and nyalldawson committed Sep 6, 2021
1 parent c1dcb2c commit 9020ac548a2fc20bfaa9c3a203ffd5ed70d0ebba
@@ -44,6 +44,7 @@ class TestQgisAppPython : public QObject
void plugins();
void pythonPlugin();
void pluginMetadata();
void pythonPluginDependencyOrder();
void runString();
void evalString();

@@ -125,6 +126,22 @@ void TestQgisAppPython::pluginMetadata()
QVERIFY( mQgisApp->mPythonUtils->pluginHasProcessingProvider( QStringLiteral( "ProcessingPluginTest" ) ) );
}

void TestQgisAppPython::pythonPluginDependencyOrder()
{
QVERIFY( mQgisApp->mPythonUtils->pluginList().contains( QStringLiteral( "PluginPathTest" ) ) );
QVERIFY( mQgisApp->mPythonUtils->pluginList().contains( QStringLiteral( "dependent_plugin_1" ) ) );
QVERIFY( mQgisApp->mPythonUtils->pluginList().contains( QStringLiteral( "dependent_plugin_2" ) ) );

const int indexIndependentPlugin = mQgisApp->mPythonUtils->pluginList().indexOf( QStringLiteral( "PluginPathTest" ) );
const int indexDependentPlugin1 = mQgisApp->mPythonUtils->pluginList().indexOf( QStringLiteral( "dependent_plugin_1" ) );
const int indexDependentPlugin2 = mQgisApp->mPythonUtils->pluginList().indexOf( QStringLiteral( "dependent_plugin_2" ) );

// Dependent plugins should appear in this list after their dependencies,
// since that's the order in which they'll be loaded to QGIS
QVERIFY( indexIndependentPlugin < indexDependentPlugin1 );
QVERIFY( indexDependentPlugin1 < indexDependentPlugin2 );
}

void TestQgisAppPython::runString()
{
QVERIFY( mQgisApp->mPythonUtils->runString( "a=1+1" ) );
@@ -0,0 +1,22 @@
from PyQt5.QtWidgets import QAction


def classFactory(iface):
return DependentPlugin1(iface)


class DependentPlugin1:
def __init__(self, iface):
self.iface = iface

def initGui(self):
self.action = QAction('Go!', self.iface.mainWindow())
self.action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.action)

def unload(self):
self.iface.removeToolBarIcon(self.action)
del self.action

def run(self):
pass
@@ -0,0 +1,7 @@
[general]
name=Dependent plugin 1
description=A dependent plugin
version=1.0
qgisMinimumVersion=3.0
author=Germán Carrillo
plugin_dependencies=plugin path test
@@ -0,0 +1,22 @@
from PyQt5.QtWidgets import QAction


def classFactory(iface):
return DependentPlugin2(iface)


class DependentPlugin2:
def __init__(self, iface):
self.iface = iface

def initGui(self):
self.action = QAction('Go!', self.iface.mainWindow())
self.action.triggered.connect(self.run)
self.iface.addToolBarIcon(self.action)

def unload(self):
self.iface.removeToolBarIcon(self.action)
del self.action

def run(self):
pass
@@ -0,0 +1,7 @@
[general]
name=Dependent plugin 2
description=Yet another dependent plugin
version=1.0
qgisMinimumVersion=3.0
author=Germán Carrillo
plugin_dependencies=Dependent plugin 1

0 comments on commit 9020ac5

Please sign in to comment.