Fix tests and code

This commit is contained in:
Tim Bentley 2018-12-02 10:19:07 +00:00
parent eeefc81174
commit c7fe441087
2 changed files with 11 additions and 13 deletions

View File

@ -87,8 +87,8 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Give all the plugins a chance to perform some tasks at startup Give all the plugins a chance to perform some tasks at startup
""" """
self.application.process_events() self.application.process_events()
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.is_active(): if plugin and plugin.is_active():
plugin.app_startup() plugin.app_startup()
self.application.process_events() self.application.process_events()
@ -98,7 +98,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Create the plugins' media manager items. Create the plugins' media manager items.
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.create_media_manager_item() plugin.create_media_manager_item()
def hook_settings_tabs(self): def hook_settings_tabs(self):
@ -109,7 +109,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.create_settings_tab(self.settings_form) plugin.create_settings_tab(self.settings_form)
def hook_import_menu(self): def hook_import_menu(self):
@ -119,7 +119,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.add_import_menu_item(self.main_window.file_import_menu) plugin.add_import_menu_item(self.main_window.file_import_menu)
def hook_export_menu(self): def hook_export_menu(self):
@ -128,7 +128,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
item to the export menu. item to the export menu.
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.add_export_menu_item(self.main_window.file_export_menu) plugin.add_export_menu_item(self.main_window.file_export_menu)
def hook_tools_menu(self): def hook_tools_menu(self):
@ -137,7 +137,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
item to the tools menu. item to the tools menu.
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.add_tools_menu_item(self.main_window.tools_menu) plugin.add_tools_menu_item(self.main_window.tools_menu)
@staticmethod @staticmethod
@ -148,7 +148,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
:param settings: The Settings object containing the old settings. :param settings: The Settings object containing the old settings.
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin and plugin.status is not PluginStatus.Disabled:
plugin.upgrade_settings(settings) plugin.upgrade_settings(settings)
def initialise_plugins(self): def initialise_plugins(self):
@ -185,7 +185,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to clean themselves up Loop through all the plugins and give them an opportunity to clean themselves up
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.is_active(): if plugin and plugin.is_active():
plugin.finalise() plugin.finalise()
self.log_info('Finalisation Complete for {plugin}'.format(plugin=plugin.name)) self.log_info('Finalisation Complete for {plugin}'.format(plugin=plugin.name))
@ -195,7 +195,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Return the plugin which has a name with value ``name``. Return the plugin which has a name with value ``name``.
""" """
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.name == name: if plugin and plugin.name == name:
return plugin return plugin
return None return None

View File

@ -57,8 +57,7 @@ class TestPluginManager(TestCase):
# GIVEN: A plugin manager with some mocked out methods # GIVEN: A plugin manager with some mocked out methods
manager = PluginManager() manager = PluginManager()
with patch.object(manager, 'find_plugins') as mocked_find_plugins, \ with patch.object(manager, 'hook_settings_tabs') as mocked_hook_settings_tabs, \
patch.object(manager, 'hook_settings_tabs') as mocked_hook_settings_tabs, \
patch.object(manager, 'hook_media_manager') as mocked_hook_media_manager, \ patch.object(manager, 'hook_media_manager') as mocked_hook_media_manager, \
patch.object(manager, 'hook_import_menu') as mocked_hook_import_menu, \ patch.object(manager, 'hook_import_menu') as mocked_hook_import_menu, \
patch.object(manager, 'hook_export_menu') as mocked_hook_export_menu, \ patch.object(manager, 'hook_export_menu') as mocked_hook_export_menu, \
@ -68,7 +67,6 @@ class TestPluginManager(TestCase):
manager.bootstrap_initialise() manager.bootstrap_initialise()
# THEN: The hook methods should have been called # THEN: The hook methods should have been called
mocked_find_plugins.assert_called_with()
mocked_hook_settings_tabs.assert_called_with() mocked_hook_settings_tabs.assert_called_with()
mocked_hook_media_manager.assert_called_with() mocked_hook_media_manager.assert_called_with()
mocked_hook_import_menu.assert_called_with() mocked_hook_import_menu.assert_called_with()