testserver.TestServerValue
testserver.TestServerValue(
name,
kind,
status,
value=MISSING,
error=None,
traceback=None,
)One input, output, or exported value, and how it turned out.
Returned by TestServerSession.get_input, get_output, and get_export, and held by TestServerValues.
Compares equal to the underlying value, so the common assertion needs no unwrapping:
assert ts.get_output("name") == "foo" # same as `.value == "foo"`Unless status is "ok" there is no value to compare against, and the comparison raises ValueError saying why. Returning False would let != "hi" pass for an output that never rendered or that raised, hiding the real problem behind an assertion that appears to succeed.
Comparing against another TestServerValue compares every field instead, and never raises. Because equality is against arbitrary values, instances are not hashable.
Attributes
| Name | Type | Description |
|---|---|---|
| name | str | The input id, output id, or export name. |
| kind | ValueKind |
Which of the three this is. |
| status | ValueStatus |
* "ok" — produced a value, available as value. * "error" — raised; see error and traceback. * "silent" — the most recent render produced nothing, because a req() failed (any SilentException). The browser blanks such an output, so it has no value here either, even if an earlier render produced one. An output reading an input that has not been set is silent, and so is a render.plot until the client’s width and height are supplied. * "never-rendered" — has not run at all yet, so it has produced neither a value, nor an error, nor a silent render. An output that is hidden (and so suspended) is never-rendered until it becomes visible. There is no status for “does not exist”: a TestServerValue always describes something real, and asking for a name that is not there raises KeyError instead. |
| value | Any | The value, JSON round-tripped as it would be sent to the browser, so its shape depends on the renderer. MISSING unless status is "ok" – not None, which a renderer can legitimately produce. (MISSING is not JSON-serializable, so json.dumps(dataclasses.asdict(values)) needs default=str; dict() omits the key instead.) |
| error | Optional[str] | The error message, or None unless status is "error". |
| traceback | Optional[str] | The formatted traceback of error, or None when there is no error. Recorded only in test mode, and never sent to the browser. |
See Also
Methods
| Name | Description |
|---|---|
| keys | Return the keys dict(value) produces. |
keys
testserver.TestServerValue.keys()Return the keys dict(value) produces.
Keyed on status, not on inspecting value: an item that produced no value has no value key at all, rather than one holding MISSING. That also keeps the dictionary form JSON-serializable.