Add an interface test for the find_plugins method.

Not sure if this should be an interface test or a scenario test, but it does very little mocking, tries to let the bits of OpenLP run for real, and checks that all the plugins are imported.

Remove the superfluous argument to the find_plugins method.
This commit is contained in:
Raoul Snyman 2013-02-11 23:16:30 +02:00
parent b5f3e46ad4
commit 98311d9ad1
5 changed files with 76 additions and 13 deletions

View File

@ -61,21 +61,16 @@ class PluginManager(object):
self.plugins = [] self.plugins = []
log.info(u'Plugin manager Initialised') log.info(u'Plugin manager Initialised')
def find_plugins(self, plugin_dir): def find_plugins(self):
""" """
Scan the directory ``plugin_dir`` for objects inheriting from the Scan a directory for objects inheriting from the ``Plugin`` class.
``Plugin`` class.
``plugin_dir``
The directory to scan.
""" """
log.info(u'Finding plugins') log.info(u'Finding plugins')
start_depth = len(os.path.abspath(plugin_dir).split(os.sep)) start_depth = len(os.path.abspath(self.base_path).split(os.sep))
present_plugin_dir = os.path.join(plugin_dir, 'presentations') present_plugin_dir = os.path.join(self.base_path, 'presentations')
log.debug(u'finding plugins in %s at depth %d', unicode(plugin_dir), start_depth) log.debug(u'finding plugins in %s at depth %d', unicode(self.base_path), start_depth)
for root, dirs, files in os.walk(plugin_dir): for root, dirs, files in os.walk(self.base_path):
if sys.platform == 'darwin'and root.startswith(present_plugin_dir): if sys.platform == 'darwin' and root.startswith(present_plugin_dir):
# TODO Presentation plugin is not yet working on Mac OS X. # TODO Presentation plugin is not yet working on Mac OS X.
# For now just ignore it. The following code will ignore files from the presentation plugin directory # For now just ignore it. The following code will ignore files from the presentation plugin directory
# and thereby never import the plugin. # and thereby never import the plugin.

View File

@ -551,7 +551,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# Define the media Dock Manager # Define the media Dock Manager
self.mediaDockManager = MediaDockManager(self.mediaToolBox) self.mediaDockManager = MediaDockManager(self.mediaToolBox)
log.info(u'Load Plugins') log.info(u'Load Plugins')
self.plugin_manager.find_plugins(plugin_path) self.plugin_manager.find_plugins()
# hook methods have to happen after find_plugins. Find plugins needs # hook methods have to happen after find_plugins. Find plugins needs
# the controllers hence the hooks have moved from setupUI() to here # the controllers hence the hooks have moved from setupUI() to here
# Find and insert settings tabs # Find and insert settings tabs

View File

@ -0,0 +1,8 @@
import sip
sip.setapi(u'QDate', 2)
sip.setapi(u'QDateTime', 2)
sip.setapi(u'QString', 2)
sip.setapi(u'QTextStream', 2)
sip.setapi(u'QTime', 2)
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)

View File

@ -0,0 +1,60 @@
"""
Package to test the openlp.core.lib.pluginmanager package.
"""
import os
import sys
from tempfile import mkstemp
from unittest import TestCase
from mock import MagicMock, patch
from PyQt4 import QtGui
from openlp.core.lib.pluginmanager import PluginManager
from openlp.core.lib import Registry, Settings
class TestPluginManager(TestCase):
"""
Test the PluginManager class
"""
def setUp(self):
"""
Some pre-test setup required.
"""
fd, self.ini_file = mkstemp(u'.ini')
Settings().set_filename(self.ini_file)
Registry.create()
Registry().register(u'service_list', MagicMock())
self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.plugins_dir = os.path.abspath(os.path.join(os.path.basename(__file__), u'..', u'openlp', u'plugins'))
def tearDown(self):
os.unlink(self.ini_file)
def find_plugins_test(self):
"""
Test the find_plugins() method to ensure it imports the correct plugins.
"""
# GIVEN: A plugin manager
plugin_manager = PluginManager(self.plugins_dir)
# WHEN: We mock out sys.platform to make it return "darwin" and then find the plugins
old_platform = sys.platform
sys.platform = u'darwin'
plugin_manager.find_plugins()
sys.platform = old_platform
# THEN: We should find the "Songs", "Bibles", etc in the plugins list
plugin_names = [plugin.name for plugin in plugin_manager.plugins]
assert u'songs' in plugin_names, u'There should be a "songs" plugin.'
assert u'bibles' in plugin_names, u'There should be a "bibles" plugin.'
assert u'presentations' not in plugin_names, u'There should NOT be a "presentations" plugin.'
assert u'images' in plugin_names, u'There should be a "images" plugin.'
assert u'media' in plugin_names, u'There should be a "media" plugin.'
assert u'custom' in plugin_names, u'There should be a "custom" plugin.'
assert u'songusage' in plugin_names, u'There should be a "songusage" plugin.'
assert u'alerts' in plugin_names, u'There should be a "alerts" plugin.'
assert u'remotes' in plugin_names, u'There should be a "remotes" plugin.'