def load_task(path: str) -> "Task": try: task = utils.load_from_path(path, Task) except exceptions.LoadFromPathError as exc: raise exceptions.TaskNotFound(f"Task at {path} cannot be imported: {str(exc)}") return task
def from_path(cls, dotted_path: str) -> "App": """ Create an :py:class:`App` object by dynamically loading the object at the given path. Parameters ---------- dotted_path : Dotted path to the object to load (e.g. ``mymodule.submodule.procrastinate_app``) """ return utils.load_from_path(dotted_path, cls)
def test_load_from_path_wrong_type(): with pytest.raises(exceptions.LoadFromPathError): utils.load_from_path("json.loads", int)
def test_load_from_path_error(input): with pytest.raises(ImportError): utils.load_from_path(input, types.FunctionType)
def test_load_from_path(): loads = utils.load_from_path("json.loads", types.FunctionType) import json assert loads is json.loads
def from_path(cls, dotted_path: str): return utils.load_from_path(dotted_path, cls)