nixos/test-driver: rm global logger
We remove the global rootlog in favor of instantiating the logger as required in the __init__.py and pass it down as a parameter (of our AbstractLogger type).
This commit is contained in:
@@ -2,7 +2,7 @@ import time
|
||||
from math import isfinite
|
||||
from typing import Callable, Optional
|
||||
|
||||
from .logger import rootlog
|
||||
from test_driver.logger import AbstractLogger
|
||||
|
||||
|
||||
class PollingConditionError(Exception):
|
||||
@@ -13,6 +13,7 @@ class PollingCondition:
|
||||
condition: Callable[[], bool]
|
||||
seconds_interval: float
|
||||
description: Optional[str]
|
||||
logger: AbstractLogger
|
||||
|
||||
last_called: float
|
||||
entry_count: int
|
||||
@@ -20,11 +21,13 @@ class PollingCondition:
|
||||
def __init__(
|
||||
self,
|
||||
condition: Callable[[], Optional[bool]],
|
||||
logger: AbstractLogger,
|
||||
seconds_interval: float = 2.0,
|
||||
description: Optional[str] = None,
|
||||
):
|
||||
self.condition = condition # type: ignore
|
||||
self.seconds_interval = seconds_interval
|
||||
self.logger = logger
|
||||
|
||||
if description is None:
|
||||
if condition.__doc__:
|
||||
@@ -41,7 +44,7 @@ class PollingCondition:
|
||||
if (self.entered or not self.overdue) and not force:
|
||||
return True
|
||||
|
||||
with self, rootlog.nested(self.nested_message):
|
||||
with self, self.logger.nested(self.nested_message):
|
||||
time_since_last = time.monotonic() - self.last_called
|
||||
last_message = (
|
||||
f"Time since last: {time_since_last:.2f}s"
|
||||
@@ -49,13 +52,13 @@ class PollingCondition:
|
||||
else "(not called yet)"
|
||||
)
|
||||
|
||||
rootlog.info(last_message)
|
||||
self.logger.info(last_message)
|
||||
try:
|
||||
res = self.condition() # type: ignore
|
||||
except Exception:
|
||||
res = False
|
||||
res = res is None or res
|
||||
rootlog.info(self.status_message(res))
|
||||
self.logger.info(self.status_message(res))
|
||||
return res
|
||||
|
||||
def maybe_raise(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user