Example #1
0
def quaternion(draw, x=float64(), y=float64(), z=float64(), w=float64()):
    """
    Generate value for ROS geometry message type "quaternion".

    Parameters
    ----------
    x : hypothesis.strategies.floats()
        Strategy to generate x value. (Default: Default hypothesis strategy.)
    y : hypothesis.strategies.floats()
        Strategy to generate y value. (Default: Default hypothesis strategy.)
    z : hypothesis.strategies.floats()
        Strategy to generate z value. (Default: Default hypothesis strategy.)
    w : hypothesis.strategies.floats()
        Strategy to generate w value. (Default: Default hypothesis strategy.)

    """
    x_value, y_value, z_value, w_value = draw(x), draw(y), draw(z), draw(w)
    assert isinstance(
        x_value,
        float), 'drew invalid x={x_value} from {x} for float64 field'.format(
            x_value, x)
    assert isinstance(
        y_value,
        float), 'drew invalid y={y_value} from {y} for float64 field'.format(
            y_value, y)
    assert isinstance(
        z_value,
        float), 'drew invalid y={z_value} from {z} for float64 field'.format(
            z_value, z)
    assert isinstance(
        w_value,
        float), 'drew invalid y={w_value} from {w} for float64 field'.format(
            w_value, w)
    return _Quaternion(x_value, y_value, z_value, w_value)
Example #2
0
def camera_info(draw,
                header=header(),
                height=uint32(),
                width=uint32(),
                distortion_model=string(),
                D=array(elements=float64()),
                K=array(elements=float64(), min_size=9, max_size=9),
                R=array(elements=float64(), min_size=9, max_size=9),
                P=array(elements=float64(), min_size=12, max_size=12),
                binning_x=uint32(),
                binning_y=uint32(),
                roi=region_of_interest()):
    """
    Generate values for ROS1 sensor_msgs/CameraInfo.msg.
    """
    header_value = draw(header)
    height_value = draw(height)
    width_value = draw(width)
    distortion_model_value = draw(distortion_model)
    d_value = draw(D)
    k_value = draw(K)
    r_value = draw(R)
    p_value = draw(P)
    binning_x_value = draw(binning_x)
    binning_y_value = draw(binning_y)
    roi_value = draw(roi)
    return _CameraInfo(header_value, height_value, width_value,
                       distortion_model_value, d_value, k_value, r_value,
                       p_value, binning_x_value, binning_y_value, roi_value)
Example #3
0
def imu(draw,
        header=header(),
        orientation=quaternion(),
        orientation_covariance=array(elements=float64(),
                                     min_size=9,
                                     max_size=9),
        angular_velocity=vector3(),
        angular_velocity_covariance=array(elements=float64(),
                                          min_size=9,
                                          max_size=9),
        linear_acceleration=vector3(),
        linear_acceleration_covariance=array(elements=float64(),
                                             min_size=9,
                                             max_size=9)):
    """
    Generate values for ROS1 sensor_msgs/Imu.msg.

    Parameters
    ----------
    header : hypothesis_ros.std_msgs.header()
        Strategy to generate header value. (Default: Default hypothesis_ros strategy.)
    orientation : hypothesis_ros.geometry_msgs.Quaternion()
        Strategy to generate orientation value. (Default: Default hypothesis_ros strategy.)
    orientation_covariance : hypothesis_ros.message_fields.array()
        Strategy to generate orientation_covariance value. (Default: Customized to 9 elements of type float64().)
    angular_velocity : hypothesis_ros.messages.geometry_msgs.vector3()
        Strategy to generate angular_velocity value. (Default: Default hypothesis_ros strategy.)
    angular_velocity_covariance : hypothesis_ros.message_fields.array()
        Strategy to generate angular_velocity_covariance value. (Default: Customized to 9 elements of type float64().)
    linear_acceleration : hypothesis_ros.messages.geometry_msgs.vector3()
        Strategy to generate linear_acceleration value. (Default: Default hypothesis_ros strategy.)
    linear_acceleration_covariance : hypothesis_ros.messages.message_fields.array()
        Strategy to generate linear_acceleration_covariance value. (Default: Customized to 9 elements of type float64().)

    """
    header_value = draw(header)
    orientation_value = draw(orientation)
    orientation_covariance_value = draw(orientation_covariance)
    angular_velocity_value = draw(angular_velocity)
    angular_velocity_covariance_value = draw(angular_velocity_covariance)
    linear_acceleration_value = draw(linear_acceleration)
    linear_acceleration_covariance_value = draw(linear_acceleration_covariance)
    # TODO: add validation
    return _Imu(header_value, orientation_value, orientation_covariance_value,
                angular_velocity_value, angular_velocity_covariance_value,
                linear_acceleration_value,
                linear_acceleration_covariance_value)
Example #4
0
def pose_with_covariance(draw,
                         pose=pose(),
                         covariance=array(elements=float64(),
                                          min_size=36,
                                          max_size=36)):
    """
    Generate value for ROS geometry message type "PoseWithCovariance".
    """
    pose_value, covariance_value = draw(pose), draw(covariance)
    # TODO: add validation for covariance_value
    return _PoseWithCovariance(pose_value, covariance_value)
Example #5
0
from hypothesis_ros.message_fields import (
    array,
    float64,
    uint32,
    time,
)


@given(
    array(elements=transform_stamped(
        header(seq=uint32(min_value=0, max_value=0),
               stamp=time(secs=uint32(min_value=1, max_value=1),
                          nsecs=uint32(min_value=2, max_value=2)),
               frame_id=just('some_tf_frame_name')),
        just('some_child_frame_id'),
        transform(translation=vector3(x=float64(min_value=1.0, max_value=1.0),
                                      y=float64(min_value=2.0, max_value=2.0),
                                      z=float64(min_value=3.0, max_value=3.0)),
                  rotation=quaternion(x=float64(min_value=1.0, max_value=1.0),
                                      y=float64(min_value=2.0, max_value=2.0),
                                      z=float64(min_value=3.0, max_value=3.0),
                                      w=float64(min_value=4.0,
                                                max_value=4.0)))),
          min_size=2,
          max_size=2))
def test_tfmessage_accepts_customized_strategies(generated_value):
    """Exemplary customized TFMessage."""
    assert generated_value == [
        ((0, (1, 2), 'some_tf_frame_name'), 'some_child_frame_id',
         ((1.0, 2.0, 3.0), (1.0, 2.0, 3.0, 4.0))),
        ((0, (1, 2), 'some_tf_frame_name'), 'some_child_frame_id',
                          width=uint32(min_value=4, max_value=4),
                          do_rectify=just(True)
                         )
      )
def test_region_of_interest_accepts_customized_strategies(generated_values):
    """Exemplary customized region_of_interest message fields."""
    assert generated_values == (1, 2, 3, 4, True)


@given(imu(header(seq=uint32(min_value=0, max_value=0),
                  stamp=time(secs=uint32(min_value=1, max_value=1),
                             nsecs=uint32(min_value=2, max_value=2)
                            ),
                  frame_id=just('some_tf_frame_name')
                 ),
           quaternion(x=float64(min_value=1.0, max_value=1.0),
                      y=float64(min_value=2.0, max_value=2.0),
                      z=float64(min_value=3.0, max_value=3.0),
                      w=float64(min_value=4.0, max_value=4.0)
                     ),
           array(elements=float64(min_value=1.0, max_value=1.0), min_size=9, max_size=9),
           vector3(x=float64(min_value=1.0, max_value=1.0),
                   y=float64(min_value=2.0, max_value=2.0),
                   z=float64(min_value=3.0, max_value=3.0)
                  ),
           array(elements=float64(min_value=2.0, max_value=2.0), min_size=9, max_size=9),
           vector3(x=float64(min_value=1.0, max_value=1.0),
                   y=float64(min_value=2.0, max_value=2.0),
                   z=float64(min_value=3.0, max_value=3.0)
                  ),
           array(elements=float64(min_value=3.0, max_value=3.0), min_size=9, max_size=9)

@given(float32())
def test_float32_generates_in_range_value_per_default(generated_value):
    """Verify default value range for Float32."""
    assert generated_value >= FLOAT32_MIN_VALUE
    assert generated_value <= FLOAT32_MAX_VALUE


# def test_float32_with_invalid_min_value_raises_exception():
#     """Verifies validation of Float32 min_value (lower limit)."""
#     with raises(InvalidArgument):
#         float32(min_value = FLOAT32_MIN_VALUE - 0.1).example()


@given(float64())
def test_float64_generates_expected_min_value_as_default(generated_value):
    """Verify default min. generated value for Float64."""
    assert generated_value >= FLOAT64_MIN_VALUE
    assert generated_value <= FLOAT64_MAX_VALUE


# def test_float64_with_invalid_min_value_raises_exception():
#     """Verifies validation of Float64 min_value (lower limit)."""
#     with raises(InvalidArgument):
#         float64(min_value = FLOAT64_MIN_VALUE - 0.1).example()


@given(string())
def test_string_generates_in_range_size_per_default(generated_value):
    """Verify default generated string size."""
    pose_with_covariance,
    pose_with_covariance_stamped,
    vector3,
    quaternion,
    transform,
    transform_stamped
)
from hypothesis_ros.message_fields import (
    array,
    float64,
    uint32,
    time
)


@given(point(x=float64(min_value=1.0, max_value=1.0),
             y=float64(min_value=2.0, max_value=2.0),
             z=float64(min_value=3.0, max_value=3.0)
            )
      )
def test_point_accepts_customized_strategies(generated_value):
    """Exemplary customized point."""
    assert generated_value == (1.0, 2.0, 3.0)


@given(quaternion(x=float64(min_value=1.0, max_value=1.0),
                  y=float64(min_value=2.0, max_value=2.0),
                  z=float64(min_value=3.0, max_value=3.0),
                  w=float64(min_value=4.0, max_value=4.0)
                 )
      )