Documentation Index
Fetch the complete documentation index at: https://docs.roboticks.io/llms.txt
Use this file to discover all available pages before exploring further.
Assertions
roboticks.assertions ships five rclpy-aware assertion helpers. Each one spins a node briefly, evaluates a predicate, and raises AssertionError (or TimeoutError) with an informative message on failure.
assert_topic_published
Wait until a message matching the predicate is published on topic.
Signature
| Parameter | Type | Default | Description |
|---|---|---|---|
topic | str | — | Fully-qualified topic (e.g. /cmd_vel). |
msg_type | message class | — | The ROS2 message class to subscribe with. |
within | float | 5.0 | Wall-clock seconds to wait. |
predicate | Callable[[msg], bool] | accept-first | Filter — wait for the first message that returns True. |
qos | QoSProfile | rclpy default | Subscription QoS. |
node | Node | ephemeral | Use an existing node instead of spinning a one-shot subscriber. |
Raises
TimeoutError— no matching message inwithinseconds.RuntimeError— rclpy not initialised, topic type mismatch.
Returns
The first message matching the predicate, as a deserialised Python object ofmsg_type.
Example
assert_service_response
Send a request, wait for the response.
Signature
Raises
TimeoutError— service unavailable or response not received inwithinseconds.RuntimeError— rclpy not initialised, service type mismatch.
Returns
The deserialised response object.Example
assert_action_result
Send a goal, wait for the terminal result (success or failure).
Signature
| Parameter | Description |
|---|---|
action | Action name (e.g. /navigate_to_pose). |
action_type | The ROS2 action class. |
goal | A <ActionType>.Goal() instance. |
within | Seconds to wait for a terminal result. |
feedback_cb | Optional callback fired on each feedback message. |
Raises
TimeoutError— no terminal result inwithinseconds.AssertionError— goal rejected by action server.RuntimeError— rclpy not initialised.
Returns
The completedClientGoalHandle. Access .result() for the action-specific result.
Example
assert_param_equals
Read a parameter from a node and assert its value.
Signature
| Parameter | Description |
|---|---|
node_name | Fully-qualified node name (e.g. /nav2_planner). |
param | Parameter name. |
expected | Expected value. Comparison is ==. |
within | Seconds to wait for the param service to be available. |
Raises
TimeoutError— parameter service unavailable.AssertionError— parameter value doesn’t matchexpected.RuntimeError— node doesn’t exist, parameter not declared.
Example
assert_tf_transform
Wait until a TF transform from source_frame to target_frame is available, then assert on its components.
Signature
| Parameter | Description |
|---|---|
source_frame | Source TF frame ID. |
target_frame | Target TF frame ID. |
within | Seconds to wait for the transform. |
translation | Optional expected (x, y, z) — asserted within tol. |
rotation | Optional expected quaternion (x, y, z, w) — asserted within tol. |
tol | Tolerance for translation/rotation comparison. |
Raises
TimeoutError— TF transform not available.AssertionError— translation/rotation deviates beyondtol.
Returns
Thegeometry_msgs/msg/TransformStamped object.
Example
Shared semantics
| Concern | Behaviour |
|---|---|
| Node reuse | All helpers accept node= to share a long-lived node. Defaults to an ephemeral node created per-call. |
| Threading | Each helper internally spins on a SingleThreadedExecutor for the duration of the wait. Safe to call from pytest’s default sync runner. |
| rclpy.init | Caller must have called rclpy.init() (typical in a session-scoped fixture). |
| Cancellation | Test framework SIGINT (Ctrl-C) cleanly aborts the wait. |
| Logging | Each helper logs to the roboticks.assertions logger at DEBUG. |
Next
Fault injection
Pair assertions with fault injection for negative tests.
Writing tests in pytest
Worked examples that put these helpers in context.
MCAP capture
Record bag files when assertions fail.
Launch testing
System-test patterns that use these helpers across processes.