def load_plugins(self): with indent(4): logger.debug("PLUGINS: %s", self._settings['PLUGINS']) for plugin in self._settings['PLUGINS']: for class_name, cls in import_string(plugin): if issubclass(cls, MachineBasePlugin ) and cls is not MachineBasePlugin: logger.debug( "Found a Machine plugin: {}".format(plugin)) storage = PluginStorage(class_name) instance = cls(SlackClient(), self._settings, storage) missing_settings = self._register_plugin( class_name, instance) if missing_settings: show_invalid(class_name) with indent(4): error_msg = "The following settings are missing: {}".format( ", ".join(missing_settings)) puts(colored.red(error_msg)) puts( colored.red( "This plugin will not be loaded!")) del instance else: instance.init() show_valid(class_name) self._storage.set('manual', dill.dumps(self._help))
def load_plugins(self): with indent(4): logger.debug("PLUGINS: %s", self._settings['PLUGINS']) for plugin in self._settings['PLUGINS']: for class_name, cls in import_string(plugin): if MachineBasePlugin in cls.__bases__ and cls is not MachineBasePlugin: logger.debug("Found a Machine plugin: {}".format(plugin)) storage = PluginStorage(class_name) instance = cls(self._settings, MessagingClient(), storage) self._register_plugin(class_name, instance) show_valid(class_name)
def test_import_all_classes(): classes = import_string('tests.fake_classes') assert len(classes) == 2 # convert list of tuples into dict so it's easier to assert classes_dict = dict(classes) assert 'tests.fake_classes:FakeA' in classes_dict assert inspect.isclass(classes_dict['tests.fake_classes:FakeA']) assert classes_dict['tests.fake_classes:FakeA'].__name__ == 'FakeA' assert 'tests.fake_classes:FakeB' in classes_dict assert inspect.isclass(classes_dict['tests.fake_classes:FakeB']) assert classes_dict['tests.fake_classes:FakeB'].__name__ == 'FakeB' assert 'fake_function' not in classes_dict
def __init__(self): _settings, _ = import_settings() _, cls = import_string(_settings['STORAGE_BACKEND'])[0] self._storage = cls(_settings)
def test_import_non_existing_class(): with pytest.raises(ImportError) as excinfo: import_string('tests.fake_classes.bla') assert "doesn't look like a module or class" in str(excinfo.value) assert "tests.fake_classes.bla" in str(excinfo.value)
def test_import_specific_class(): classes = import_string('tests.fake_classes.FakeA') assert len(classes) == 1 assert classes[0][0] == 'tests.fake_classes:FakeA' assert classes[0][1].__name__ == 'FakeA'