def test_loading(self):
        """ Test plugins loading """
        loader_mock = Mock()
        loader_mock.load.return_value = [
            PluginEntry(lambda **_: None, dict(name='cmd1')),
            PluginEntry(lambda **_: None, dict(name='cmd2')),
            PluginEntry(lambda **_: None, dict(name='cmd1')),
        ]
        loader_service_mock = Mock()
        loader_service_mock.loaders = [loader_mock]

        application = VoidApplication()
        application.depend(loader_service_mock, 'plugins_loader')
        application.depend(Mock(), 'extensions_config')
        application.depend(Mock(), 'log')

        service = Service(application)
        self.assertRaises(RuntimeError, service.get_command, 'cmd1')

        service.load()
        application.registry.log().error.assert_has_calls([
            call('Failed to register plugin %s.%s: %s', 'test_core_plugin_subsystem_control_service', ANY, ANY)
        ])
        self.assertEqual(len(service.plugins), 2)
        self.assertIsInstance(service.get_command('cmd1'), Environment)
        self.assertIsInstance(service.get_command('cmd2'), Environment)
        self.assertRaises(RuntimeError, service.get_command, 'cmd3')
    def test_plugins_loading(self):
        """ Test loading plugins """
        entries = [PluginEntry(lambda **_: None, {}), PluginEntry(lambda **_: None, {}),
                   PluginEntry(lambda **_: None, {}), PluginEntry(lambda **_: None, {'services': ['foo']})]

        loader1 = Mock()
        loader1.load.return_value = entries[:2]
        loader2 = Mock()
        loader2.load.return_value = entries[2:]

        loader_service = Mock()
        loader_service.name.return_value = 'plugins_loader'
        loader_service.loaders = [loader1, loader2]

        application = VoidApplication()
        application.depend(_PluginService)
        application.depend(ExtensionsConfig)
        application.depend(Mock(), 'log')
        application.depend(loader_service)

        plugin_service = application.registry.get_service(_PluginService)
        plugin_service.load()
        self.assertEqual(len(plugin_service.plugins), 3)
    def test_loading(self):
        """ Test plugins loading """
        loader_mock = Mock()
        loader_mock.load.return_value = [
            PluginEntry(lambda **_: None, dict(type='schedule', schedule='@minutely')),
            PluginEntry(lambda **_: None, dict(type='bootstrap')),
            PluginEntry(lambda **_: None, dict(type='daemon')),
        ]
        loader_service_mock = Mock()
        loader_service_mock.loaders = [loader_mock]

        application = VoidApplication()
        application.depend(loader_service_mock, 'plugins_loader')
        application.depend(Mock(), 'extensions_config')
        application.depend(Mock(), 'log')

        service = Service(application)
        self.assertRaises(RuntimeError, lambda: service.schedule_plugins)

        service.load()
        self.assertEqual(len(service.plugins), 3)
        self.assertEqual(len(service.schedule_plugins), 1)
        self.assertEqual(len(service.daemon_plugins), 1)
        self.assertEqual(len(service.bootstrap_plugins), 1)