def load_services(services): for service in services: service_plugins[service] = {} service_config = cf.config('config:' + service) if service_config is None: logger.error("Service `%s' has no config section" % service) sys.exit(1) service_plugins[service]['config'] = service_config module = cf.g('config:' + service, 'module', service) modulefile = resource_filename('mqttwarn.services', module + '.py') try: service_plugins[service]['module'] = load_module(modulefile) logger.info('Successfully loaded service "{}"'.format(service)) except Exception as ex: logger.exception('Unable to load service "{}" from file "{}": {}'.format(service, modulefile, ex))
def test_load_module(): module = load_module('mqttwarn/services/file.py') assert 'plugin' in dir(module) assert module.plugin.__code__.co_argcount == 2 assert 'srv' in module.plugin.__code__.co_varnames assert 'item' in module.plugin.__code__.co_varnames