[core/module] fix failing unit test

wrong error handling again
This commit is contained in:
tobi-wan-kenobi 2021-01-17 15:29:44 +01:00
parent beca26c2bf
commit a27c284869

View file

@ -17,8 +17,6 @@ except Exception as e:
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
import sys
"""Loads a module by name """Loads a module by name
:param module_name: Name of the module to load :param module_name: Name of the module to load
@ -47,16 +45,16 @@ def load(module_name, config=core.config.Config([]), theme=None):
return getattr(mod, "Module")(config, theme) return getattr(mod, "Module")(config, theme)
except ImportError as e: except ImportError as e:
usermod = os.path.expanduser("~/.config/bumblebee-status/modules/{}.py".format(module_short)) usermod = os.path.expanduser("~/.config/bumblebee-status/modules/{}.py".format(module_short))
if not os.path.exists(usermod): if os.path.exists(usermod):
raise e try:
try: log.warning("failed to import {} from system: {}".format(module_short, e))
log.warning("failed to import {} from system: {}".format(module_short, e)) mod = importlib.machinery.SourceFileLoader("modules.{}".format(module_short),
mod = importlib.machinery.SourceFileLoader("modules.{}".format(module_short), os.path.expanduser(usermod)).load_module()
os.path.expanduser(usermod)).load_module() log.debug("importing {} from user".format(module_short))
log.debug("importing {} from user".format(module_short)) return getattr(mod, "Module")(config, theme)
return getattr(mod, "Module")(config, theme) except ImportError as e:
except ImportError as e: log.fatal("import failed: {}".format(e))
log.fatal("failed to import {}: {}".format(module_short, e)) log.fatal("failed to import {}".format(module_short))
return Error(config=config, module=module_name, error="unable to load module") return Error(config=config, module=module_name, error="unable to load module")