faults — functions
Breaking a camera on purpose, so your error handling can be tested.
Nothing here is a feature of a camera and nothing here does anything to one. Every call refuses a real device outright and works only on a simulated camera, so a call that reached a production build stops being silent the first time it runs against hardware.
That is also why these are free functions in a module of their own
rather than methods on
optris_sdk.camera.Camera, mirroring the ABI's own naming:
these entry points carry a testing prefix and deliberately not
the imager one every camera call has, because they are not things
a camera does -- they are things a test does to a camera.
(Spelled in words rather than with the two prefixes, because
FfiMatchesTheLibrary scans this file for ABI names and a prefix
ending in an underscore reads to it as an entry point that does not
exist. That guard is right to: the scan is on the name, and a prose
mention of a call that is not in the header is exactly the drift it
catches.)
What this does not do. It does not make a camera come back. A
simulated camera has no device to re-open, so the SDK's attempts
against it fail and the schedule runs to RECONNECT_GAVE_UP. That
is the right shape for testing what an application shows during an
outage and when recovery is abandoned, and the wrong tool for testing
what it does when a camera returns -- that needs a simulated camera
which genuinely re-opens, which does not exist yet.
fake_connection_event(camera, status, message = '')
Publish a connection state the camera is not in.
Drives whatever camera.on_connection_status and
camera.on_reconnect are subscribed to, exactly as a real event
would, so an application can exercise the branch it has never
seen::
camera.enable_auto_reconnect()
camera.on_reconnect(lambda event: stages.append(event.phase))
optris_sdk.faults.fake_connection_lost(camera, 'the test')
Raises optris_sdk.errors.NotSupportedError for a real
camera, a recording or a still.
- Parameter
camera— the camera to lie to. Must be simulated. - Parameter
status— one ofCONNECTION_LOST,CONNECTION_STALLED,CONNECTION_FAILEDorCONNECTION_DISCONNECTED.CONNECTION_CONNECTINGandCONNECTION_CONNECTEDare refused withoptris_sdk.errors.InvalidArgumentError: those two are the SDK's own answers about work it did, and a handler told the camera is back when nothing opened is being misled in the direction that hides a fault rather than inventing one. - Parameter
message— detail carried to the handler, as a real event's is.
fake_connection_lost(camera, message = 'a faked connection loss')
Pretend the link was lost. fake_connection_event with
CONNECTION_LOST.
fake_connection_stalled(camera, message = 'a faked stall')
Pretend frames stopped arriving while the link stayed up.
fake_connection_event with CONNECTION_STALLED.
fake_connection_failed(camera, message = 'a faked failure')
Pretend an open failed. fake_connection_event with
CONNECTION_FAILED.
fake_disconnect(camera, message = 'a faked disconnect')
Pretend the camera was disconnected deliberately.
CONNECTION_DISCONNECTED is where a cancelled attempt rests,
and CONNECTION_FAILED is where a failed one rests -- the
distinction Connect relies on, so both are worth being able to
produce in a test.