def test_get_scheduled_methods_threads(): class SomePlugin(plugins.BasePlugin): @plugins.scheduled(0.4) def test_method(self): pass plugin = SomePlugin() plugin_manager = plugins.PluginManager([plugin]) interval_threads = list(plugin_manager.get_scheduled_methods_threads()) assert len(interval_threads) == 1 assert interval_threads[0]._interval == 0.4
def test_callback_wrapper_plugin_enabled(): mock_plugin = mock.MagicMock() mock_plugin.is_enalbed.return_value = True mock_func = mock.MagicMock() plugin_manager = plugins.PluginManager([]) plugin_manager._callback_wrapper(mock_func, mock_plugin, plugin_enabled=True)(foo='bar') mock_func.assert_called_once_with(foo='bar')
def test_register_plugin_signals(): signal = signalslib.Signal('test') class Plugin1(plugins.BasePlugin): @plugins.bind_signal(signal) def method(self): pass plugin1 = Plugin1() plugin_manager = plugins.PluginManager([plugin1]) plugin_manager.register_plugin_signals() assert len(signal.callbacks) == 1
def test_set_plugin_annotation_references(): class SomePlugin(plugins.BasePlugin): pass class OtherPlugin(plugins.BasePlugin): ref: SomePlugin some_plugin = SomePlugin() other_plugin = OtherPlugin() plugin_manager = plugins.PluginManager([some_plugin, other_plugin]) assert not hasattr(other_plugin, 'ref') plugin_manager.set_plugin_annotation_references() assert hasattr(other_plugin, 'ref') assert other_plugin.ref == some_plugin
def test_plugin_manager_get_marked_methods(): class SomePlugin(plugins.BasePlugin): @plugins.mark_function('test') def test_method(self): pass plugin = SomePlugin() plugin_manager = plugins.PluginManager([plugin]) marked_methods = list(plugin_manager.get_marked_methods('test')) assert len(marked_methods) == 1 assert isinstance(marked_methods[0], plugins.MarkedMethodType) assert marked_methods[0].plugin == plugin assert marked_methods[0].method == plugin.test_method assert marked_methods[0].mark.name == 'test'
def test_get_settings_widgets(): plugin1 = mock.MagicMock(spec=plugins.BasePlugin) plugin1.get_settings_widget.side_effect = NotImplementedError plugin2 = mock.MagicMock(spec=plugins.BasePlugin) plugin2.get_settings_widget.return_value = 'test' plugin3 = mock.MagicMock(spec=plugins.BasePlugin) plugin3.get_settings_widget.side_effect = ValueError plugin_manager = plugins.PluginManager([plugin1, plugin3, plugin2]) settings_widgets = list(plugin_manager.get_settings_widgets()) plugin1.get_settings_widget.assert_called_once() plugin2.get_settings_widget.assert_called_once() plugin3.get_settings_widget.assert_called_once() assert len(settings_widgets) == 1 assert settings_widgets[0] == 'test'
def main(): from PyQt5.QtWidgets import QApplication from edp import signalslib, plugins, thread, signals, journal, config, logging_tools from edp.gui.forms.main_window import MainWindow, main_window_created_signal from edp.contrib import edsm, gamestate, eddn, capi, overlay_ui from edp.settings import EDPSettings settings = EDPSettings.get_insance() logging_tools.configure(enable_sentry=settings.enable_error_reports) logger = logging.getLogger('edp') with sentry_sdk.configure_scope() as scope: scope.user = {'id': settings.user_id} scope.set_tag('platform', platform.platform()) logger.info(f'Starting, v{config.VERSION}, user={settings.user_id}') logger.info('Initializing thread manager') thread_manager = thread.ThreadManager() logger.info('Initializing flightlog journal handler') journal_reader = journal.JournalReader(settings.journal_dir) game_version = journal_reader.get_game_version_info() if game_version: scope.set_tag('game_version', game_version.version) scope.set_extra('game_build', game_version.build) logger.info('Loading plugins') settings.plugin_dir.mkdir(parents=True, exist_ok=True) plugin_loader = plugins.PluginLoader(settings.plugin_dir) plugin_loader.add_plugin(edsm.EDSMPlugin) plugin_loader.add_plugin(gamestate.GameStatePlugin) plugin_loader.add_plugin(eddn.EDDNPlugin) plugin_loader.add_plugin(discord_rich_presence.DiscordRichPresencePlugin) plugin_loader.add_plugin(inara.InaraPlugin) plugin_loader.add_plugin(capi.CapiPlugin) plugin_loader.add_plugin(overlay_ui.OverlayPlugin) plugin_loader.add_plugin(updater.UpdaterPlugin) plugin_loader.load_plugins() plugin_manager = plugins.PluginManager(plugin_loader.get_plugins()) plugin_proxy = plugins.PluginProxy(plugin_manager) def injection_config(binder: inject.Binder): binder.bind(plugins.PluginProxy, plugin_proxy) binder.bind(thread.ThreadManager, thread_manager) binder.bind(journal.JournalReader, journal_reader) for cls, obj in plugin_manager._plugins_cls_map.items(): binder.bind(cls, obj) inject.clear_and_configure(injection_config) logger.debug('Injection complete') logger.info('Configuring plugins') plugin_manager.set_plugin_annotation_references() plugin_manager.register_plugin_signals() thread_manager.add_threads( journal.JournalLiveEventThread(journal_reader), signalslib.signal_manager.get_signal_executor_thread(), *plugin_manager.get_scheduled_methods_threads() ) with thread_manager: time.sleep(0.1) # do we need this? for threads warmup signals.init_complete.emit_eager() logger.info('Initializing gui') app = QApplication([]) # app.setApplicationDisplayName('Elite Dangerous Platform') app.setApplicationVersion(config.VERSION) app.setApplicationName(config.APPNAME_SHORT) signals.app_created.emit_eager() window = MainWindow(plugin_manager) main_window_created_signal.emit_eager(window=window) window.show() try: app.exec_() finally: logger.info('App finished, exiting signal emit') signals.exiting.emit_eager()
def test_plugin_manager_get_plugin(plugin, plugins_list, result): plugin_manager = plugins.PluginManager(plugins_list) assert plugin_manager.get_plugin(plugin) == result