Skip to main content

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.
rclpy-guarded. Importing roboticks.assertions on a host without rclpy installed raises a clear RuntimeError pointing you at the ROS2 install docs. Decorators in roboticks itself are not guarded — you can import them anywhere.

assert_topic_published

Wait until a message matching the predicate is published on topic.

Signature

Raises

  • TimeoutError — no matching message in within seconds.
  • RuntimeError — rclpy not initialised, topic type mismatch.

Returns

The first message matching the predicate, as a deserialised Python object of msg_type.

Example

assert_service_response

Send a request, wait for the response.

Signature

Raises

  • TimeoutError — service unavailable or response not received in within seconds.
  • 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

Raises

  • TimeoutError — no terminal result in within seconds.
  • AssertionError — goal rejected by action server.
  • RuntimeError — rclpy not initialised.

Returns

The completed ClientGoalHandle. Access .result() for the action-specific result.

Example

assert_param_equals

Read a parameter from a node and assert its value.

Signature

Raises

  • TimeoutError — parameter service unavailable.
  • AssertionError — parameter value doesn’t match expected.
  • 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

Raises

  • TimeoutError — TF transform not available.
  • AssertionError — translation/rotation deviates beyond tol.

Returns

The geometry_msgs/msg/TransformStamped object.

Example

Shared semantics

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.