Beispiel #1
0
    def test_load_plugin_not_exists(self):
        with pytest.raises(Exception) as _:
            plugin_manager = PluginManager([os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

            plugin_manager.load_plugin('unknown')

            assert 'Cannot locate plugin "unknown"!' in self.out.getvalue().strip()
Beispiel #2
0
    def test_load_plugin_not_exists(self):
        with pytest.raises(Exception) as _:
            plugin_manager = PluginManager(
                [os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

            plugin_manager.load_plugin('unknown')

            assert 'Cannot locate plugin "unknown"!' in self.out.getvalue(
            ).strip()
Beispiel #3
0
    def test_get_available_plugins():
        plugin_manager = PluginManager([os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugins = plugin_manager.get_available_plugins()

        assert len(plugins) == 2
        assert 'test_plugin' in plugins
        assert 'name' in plugins['test_plugin']
        assert plugins['test_plugin']['name'] == 'test_plugin'
        assert 'info' in plugins['test_plugin']
Beispiel #4
0
    def test_get_available_plugins():
        plugin_manager = PluginManager(
            [os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugins = plugin_manager.get_available_plugins()

        assert len(plugins) == 2
        assert 'test_plugin' in plugins
        assert 'name' in plugins['test_plugin']
        assert plugins['test_plugin']['name'] == 'test_plugin'
        assert 'info' in plugins['test_plugin']
Beispiel #5
0
    def test_load_plugin_already_loaded(self):
        plugin_manager = PluginManager([os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugin_manager.load_plugin('test_plugin')
        plugin_manager.load_plugin('test_plugin')

        loaded_plugins = plugin_manager.get_loaded_plugins()

        assert len(loaded_plugins) == 1
        assert 'test_plugin' in loaded_plugins

        assert 'Loaded plugin "test_plugin".' in self.out.getvalue().strip()
        assert 'Plugin "test_plugin" was already loaded!' in self.out.getvalue().strip()
Beispiel #6
0
    def test_load_plugin(self):
        plugin_manager = PluginManager([os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugin_manager.load_plugin('test_plugin')

        loaded_plugins = plugin_manager.get_loaded_plugins()

        assert len(loaded_plugins) == 1
        assert 'test_plugin' in loaded_plugins
        assert 'name' in loaded_plugins['test_plugin']
        assert loaded_plugins['test_plugin']['name'] == 'test_plugin'
        assert 'info' in loaded_plugins['test_plugin']

        assert 'Loaded plugin "test_plugin".' in self.out.getvalue().strip()
Beispiel #7
0
    def test_load_plugin_already_loaded(self):
        plugin_manager = PluginManager(
            [os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugin_manager.load_plugin('test_plugin')
        plugin_manager.load_plugin('test_plugin')

        loaded_plugins = plugin_manager.get_loaded_plugins()

        assert len(loaded_plugins) == 1
        assert 'test_plugin' in loaded_plugins

        assert 'Loaded plugin "test_plugin".' in self.out.getvalue().strip()
        assert 'Plugin "test_plugin" was already loaded!' in self.out.getvalue(
        ).strip()
Beispiel #8
0
    def test_load_plugin(self):
        plugin_manager = PluginManager(
            [os.path.dirname(os.path.realpath(__file__)) + '/plugins'])

        plugin_manager.load_plugin('test_plugin')

        loaded_plugins = plugin_manager.get_loaded_plugins()

        assert len(loaded_plugins) == 1
        assert 'test_plugin' in loaded_plugins
        assert 'name' in loaded_plugins['test_plugin']
        assert loaded_plugins['test_plugin']['name'] == 'test_plugin'
        assert 'info' in loaded_plugins['test_plugin']

        assert 'Loaded plugin "test_plugin".' in self.out.getvalue().strip()
Beispiel #9
0
    def boot(self):
        # type: () -> None
        self.load_config()
        self._plugin_manager = PluginManager(
            self._configs['core']['plugins']['include'])
        for plugin in self._plugin_manager.get_available_plugins():
            if plugin not in self._disabled_plugins:
                self._plugin_manager.load_plugin(plugin)

        self.container.set_parameter('kernel.config_dir', self._config_file)
        for config_name in self._configs:
            self.container.register_singleton('config.' + config_name,
                                              self._configs[config_name])

        self.container.boot()

        for plugin in self.container.get_by_tag('plugin'):
            self._plugins.append(plugin)

        self._booted = True
Beispiel #10
0
    def boot(self):
        # type: () -> None
        self.load_config()
        self._plugin_manager = PluginManager(self._configs['core']['plugins']['include'])
        for plugin in self._plugin_manager.get_available_plugins():
            if plugin not in self._disabled_plugins:
                self._plugin_manager.load_plugin(plugin)

        self.container.set_parameter('kernel.config_dir', self._config_file)
        for config_name in self._configs:
            self.container.register_singleton('config.' + config_name, self._configs[config_name])

        self.container.boot()

        for plugin in self.container.get_by_tag('plugin'):
            self._plugins.append(plugin)

        self._booted = True
Beispiel #11
0
def create_test_kernel(user_config=None):
    # type: (Dict) -> ServiceContainer

    kernel = Kernel()

    config = create_core_test_config(user_config)

    kernel.container.register_singleton('config', config)
    kernel.container.register_singleton('pgoapi', PGoApiMock())
    kernel.container.register_singleton(
        'plugin_manager',
        PluginManager(
            os.path.dirname(os.path.realpath(__file__)) + '/plugins'))
    kernel.container.register_singleton('event_manager', EventManager())

    kernel.container.set_parameter('path_finder',
                                   config['movement']['path_finder'])
    kernel.container.set_parameter('navigator',
                                   config['movement']['path_finder'])

    return kernel
Beispiel #12
0
class Kernel(object):
    """
        The Kernel handles the creation of the app and service container.
    """
    def __init__(self):
        # type: () -> None
        self.container = ServiceContainer()
        self._plugins = []
        self._plugin_manager = None
        self._disabled_plugins = []
        self._configs = {}
        self._booted = False
        self._config_file = './config'

    def set_config_file(self, config_dir):
        self._config_file = config_dir

    def get_config_file(self):
        return self._config_file

    def load_config(self):
        # type: (str) -> None
        with open(self._config_file, 'r') as config_file:
            self._configs['core'] = ruamel.yaml.load(config_file.read(), ruamel.yaml.RoundTripLoader)

        for plugin in self._configs['core']['plugins']['exclude']:
            self.disable_plugin(plugin)

        config_dir = os.path.dirname(self._config_file)
        for plugin_config_dir in self._configs['core']['plugins']['config']:
            for node in os.listdir(os.path.join(config_dir, plugin_config_dir)):
                location = os.path.join(config_dir, plugin_config_dir, node)
                if os.path.isfile(location) and node[-4:].lower() == '.yml':
                    with open(location, 'r') as config_file:
                        module_name = node[:-4]
                        self._configs[module_name] = ruamel.yaml.load(config_file.read(), ruamel.yaml.RoundTripLoader)

    def get_config(self):
        return self._configs

    def disable_plugin(self, plugin_name):
        # type: (str) -> None
        self._disabled_plugins.append(plugin_name)

    def boot(self):
        # type: () -> None
        self.load_config()
        self._plugin_manager = PluginManager(self._configs['core']['plugins']['include'])
        for plugin in self._plugin_manager.get_available_plugins():
            if plugin not in self._disabled_plugins:
                self._plugin_manager.load_plugin(plugin)

        self.container.set_parameter('kernel.config_dir', self._config_file)
        for config_name in self._configs:
            self.container.register_singleton('config.' + config_name, self._configs[config_name])

        self.container.boot()

        for plugin in self.container.get_by_tag('plugin'):
            self._plugins.append(plugin)

        self._booted = True
Beispiel #13
0
class Kernel(object):
    """
        The Kernel handles the creation of the app and service container.
    """
    def __init__(self):
        # type: () -> None
        self.container = ServiceContainer()
        self._plugins = []
        self._plugin_manager = None
        self._disabled_plugins = []
        self._configs = {}
        self._booted = False
        self._config_file = './config'

    def set_config_file(self, config_dir):
        self._config_file = config_dir

    def get_config_file(self):
        return self._config_file

    def load_config(self):
        # type: (str) -> None
        with open(self._config_file, 'r') as config_file:
            self._configs['core'] = ruamel.yaml.load(
                config_file.read(), ruamel.yaml.RoundTripLoader)

        for plugin in self._configs['core']['plugins']['exclude']:
            self.disable_plugin(plugin)

        config_dir = os.path.dirname(self._config_file)
        for plugin_config_dir in self._configs['core']['plugins']['config']:
            for node in os.listdir(os.path.join(config_dir,
                                                plugin_config_dir)):
                location = os.path.join(config_dir, plugin_config_dir, node)
                if os.path.isfile(location) and node[-4:].lower() == '.yml':
                    with open(location, 'r') as config_file:
                        module_name = node[:-4]
                        self._configs[module_name] = ruamel.yaml.load(
                            config_file.read(), ruamel.yaml.RoundTripLoader)

    def get_config(self):
        return self._configs

    def disable_plugin(self, plugin_name):
        # type: (str) -> None
        self._disabled_plugins.append(plugin_name)

    def boot(self):
        # type: () -> None
        self.load_config()
        self._plugin_manager = PluginManager(
            self._configs['core']['plugins']['include'])
        for plugin in self._plugin_manager.get_available_plugins():
            if plugin not in self._disabled_plugins:
                self._plugin_manager.load_plugin(plugin)

        self.container.set_parameter('kernel.config_dir', self._config_file)
        for config_name in self._configs:
            self.container.register_singleton('config.' + config_name,
                                              self._configs[config_name])

        self.container.boot()

        for plugin in self.container.get_by_tag('plugin'):
            self._plugins.append(plugin)

        self._booted = True