nixos/test-driver: simplify coopmulti
This commit is contained in:
@@ -10,26 +10,16 @@ class PollingConditionFailed(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def coopmulti(fun: Callable, *, machine: Any = None) -> Callable:
|
def coopmulti(fun: Callable) -> Callable:
|
||||||
assert not (fun is None and machine is None)
|
@wraps(fun)
|
||||||
|
def wrapper(machine: Any, *args: List[Any], **kwargs: Dict[str, Any]) -> Any:
|
||||||
|
if machine.fail_early(): # type: ignore
|
||||||
|
raise PollingConditionFailed("Test interrupted early...")
|
||||||
|
|
||||||
def inner(fun_: Callable) -> Any:
|
return fun(machine, *args, **kwargs)
|
||||||
@wraps(fun_)
|
|
||||||
def wrapper(*args: List[Any], **kwargs: Dict[str, Any]) -> Any:
|
|
||||||
this_machine = args[0] if machine is None else machine
|
|
||||||
|
|
||||||
if this_machine.fail_early(): # type: ignore
|
|
||||||
raise PollingConditionFailed("Action interrupted early...")
|
|
||||||
|
|
||||||
return fun_(*args, **kwargs)
|
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
if fun is None:
|
|
||||||
return inner
|
|
||||||
else:
|
|
||||||
return inner(fun)
|
|
||||||
|
|
||||||
|
|
||||||
class PollingCondition:
|
class PollingCondition:
|
||||||
condition: Callable[[], bool]
|
condition: Callable[[], bool]
|
||||||
|
|||||||
Reference in New Issue
Block a user