tests for result wrapping

This commit is contained in:
2025-03-08 13:19:18 +01:00
parent adbc894899
commit 2262cfe45f
3 changed files with 81 additions and 8 deletions

View File

@@ -119,7 +119,7 @@ class StatusHandler:
upper_bound = DEFAULT_API_ERR_CODE
if code < lower_bound or code > upper_bound:
raise ValueError(
f"Custom error codes mus be between default "
f"Custom error codes must be between default "
f"values of {lower_bound}-{upper_bound}"
)
@@ -144,7 +144,7 @@ class StatusHandler:
api_server_error=error,
)
def unwrap(
def raise_for_status(
self,
state: Status,
) -> None:
@@ -191,6 +191,10 @@ class ResultWrapper(t.Generic[T]):
exception: Exception | None,
code_on_error: int,
) -> None:
assert (isinstance(result, NotSet) and exception is not None) or (
not isinstance(result, NotSet) and exception is None
), "set >NotSet< without exception or result with exception"
self._result = result
status: Status = STATUS_HANDLER.SUCCESS
if exception is not None:
@@ -211,6 +215,11 @@ class ResultWrapper(t.Generic[T]):
def __repr__(self) -> str:
return self.__str__()
def unwrap(self) -> T:
STATUS_HANDLER.raise_for_status(self.status)
return self.result
def wrap_result(
code_on_error: int = DEFAULT_API_ERR_CODE,