Skip to content

Commit

Permalink
Test that dependent plugins are located after their dependencies in m…
Browse files Browse the repository at this point in the history
…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 9020ac5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/src/app/testqgisapppython.cpp
Expand Up @@ -44,6 +44,7 @@ class TestQgisAppPython : public QObject
void plugins();
void pythonPlugin();
void pluginMetadata();
void pythonPluginDependencyOrder();
void runString();
void evalString();

Expand Down Expand Up @@ -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" ) );
Expand Down
22 changes: 22 additions & 0 deletions tests/testdata/test_plugin_path/dependent_plugin_1/__init__.py
@@ -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
22 changes: 22 additions & 0 deletions tests/testdata/test_plugin_path/dependent_plugin_2/__init__.py
@@ -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.