コード例 #1
0
ファイル: sensor_msgs.py プロジェクト: fkromer/hypothesis-ros
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)
コード例 #2
0
def region_of_interest(draw,  # pylint: disable=too-many-arguments
                       x_offset=uint32(),
                       y_offset=uint32(),
                       height=uint32(),
                       width=uint32(),
                       do_rectify=bool()):  # pylint: disable=no-value-for-parameter
    """
    Generate values for ROS1 sensor_msgs/RegionOfInterest.msg.

    Parameters
    ----------
    x_offset : hypothesis_ros.message_fields.uint32()
        Strategy to generate x_offset value. (Default: Default hypothesis_ros strategy.)
    y_offset : hypothesis_ros.message_fields.uint32()
        Strategy to generate y_offset value. (Default: Default hypothesis_ros strategy.)
    height : hypothesis_ros.message_fields.uint32()
        Strategy to generate height value. (Default: Default hypothesis_ros strategy.)
    width : hypothesis_ros.message_fields.uint32()
        Strategy to generate width value. (Default: Default hypothesis_ros strategy.)
    do_rectify : hypothesis_ros.message_fields.bool()
        Strategy to generate do_rectify value. (Default: Default hypothesis_ros strategy.)

    """
    x_offset_value = draw(x_offset)
    y_offset_value = draw(y_offset)
    height_value = draw(height)
    width_value = draw(width)
    do_rectify_value = draw(do_rectify)
    assert isinstance(x_offset_value, int), 'drew invalid x_offset={x_offset_value} from {x_offset} for uint32 field'.format(x_offset_value, x_offset)
    assert isinstance(y_offset_value, int), 'drew invalid y_offset={y_offset_value} from {y_offset} for uint32 field'.format(y_offset_value, y_offset)
    assert isinstance(height_value, int), 'drew invalid height={height_value} from {height} for uint32 field'.format(height_value, height)
    assert isinstance(width_value, int), 'drew invalid width={width_value} from {width} for uint32 field'.format(width_value, width)
    assert isinstance(do_rectify_value, int), 'drew invalid do_rectify={do_rectify_value} from {do_rectify} for bool field'.format(do_rectify_value, do_rectify)  # bool is subclass of int
    return _RegionOfInterest(x_offset_value, y_offset_value, height_value, width_value, do_rectify_value)
コード例 #3
0
def header(draw, seq=uint32(), stamp=time(), frame_id=string()):
    """
    Generate value for ROS1 standard message type "header".

    Parameters
    ----------
    seq : hypothesis_ros.message_fields.uint32()
        Strategy to generate seq value. (Default: Default hypothesis_ros strategy.)
    stamp : hypothesis_ros.message_fields.time()
        Strategy to generate stamp value. (Default: Default hypothesis_ros strategy.)
    frame_id : hypothesis_ros.message_fields.string()
        Strategy to generate frame_id value. (Default: Default hypothesis_ros strategy.)

    """
    seq_value = draw(seq)
    stamp_value = draw(stamp)
    frame_id_value = draw(frame_id)
    assert isinstance(
        seq_value, int
    ), 'drew invalid seq={seq_value} from {seq} for uint32 field'.format(
        seq_value, seq)
    assert isinstance(
        stamp_value.secs, int
    ), 'drew invalid stamp.secs={stamp_value} from {stamp} for int field'.format(
        stamp_value.secs, stamp)
    assert isinstance(
        stamp_value.nsecs, int
    ), 'drew invalid stamp.nsecs={stamp_value} from {stamp} for int field'.format(
        stamp_value.nsecs, stamp)
    assert isinstance(
        frame_id_value, str
    ), 'drew invalid frame_id={frame_id_value} from {frame_id} for str field'.format(
        frame_id_value, frame_id)
    return _Header(seq_value, stamp_value, frame_id_value)
コード例 #4
0
ファイル: sensor_msgs.py プロジェクト: fkromer/hypothesis-ros
def image(draw,
          header=header(),
          height=uint32(),
          width=uint32(),
          encoding=sampled_from(IMAGE_ENCODINGS),
          step=uint32(),
          is_bigendian=uint8(),
          data=array(elements=uint8(), max_size=10000**10000)):
    """
    Generate values for ROS1 sensor_msgs/Image.msg.

    Be aware that the element count of the "data" field value is not generated dependent on
    steps and rows right now. Configuration of field "data" element size requires attention
    to avoid exceptions raised in underlying hypothesis functionality.

    Parameters
    ----------
    header : hypothesis_ros.messages.std_msgs.header()
        Strategy to generate header values. (Default: Default hypothesis_ros strategy.)
    height : hypothesis_ros.message_fields.uint32()
        Strategy to generate height value. (Default: Default hypothesis_ros strategy.)
    width : hypothesis_ros.message_fields.uint32()
        Strategy to generate width value. (Default: Default hypothesis_ros strategy.)
    encoding : hypothesis.sampled_from()
        Strategy to generate encoding value. For possible values refer to
        include/sensor_msgs/image_encodings.h . (Default: hypothesis strategy with reasonable configuration.)
    is_bigendian : hypothesis_ros.message_fields.uint8()
        Strategy to generate bigendian value. (Default: Default hypothesis_ros strategy.)
    data : hypothesis_ros.message_fields.array(elements=uint8())
        Strategy to generate matrix data values. Size is steps x rows. (Default: hypothesis_ros strategy with reasonable configuration.)

    """
    header_value = draw(header)
    height_value = draw(height)
    width_value = draw(width)
    encoding_value = draw(encoding)
    step_value = draw(step)
    is_bigendian_value = draw(is_bigendian)
    data_value = draw(data)
    return _Image(header_value, height_value, width_value, encoding_value,
                  step_value, is_bigendian_value, data_value)
コード例 #5
0
from hypothesis_ros.messages.tf2_msgs import tfmessage
from hypothesis_ros.messages.geometry_msgs import (transform,
                                                   transform_stamped, vector3,
                                                   quaternion)
from hypothesis_ros.messages.std_msgs import header
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):
コード例 #6
0
def log(
    draw,  # DEBUG=uint8(), INFO=uint8(), WARN=uint8(), ERROR=uint8(), FATAL=uint8(),
    header=header(),
    level=uint8(),
    name=string(),
    msg=string(),
    file=string(),
    function=string(),
    line=uint32(),
    topics=array(elements=string())):
    """
    Generate value for ROS1 rosgraph message type "log".

    Parameters
    ----------
    header : hypothesis_ros.messages.std_msgs.header()
        Strategy to generate header value. (Default: Default hypothesis_ros strategy.)
    level : hypothesis_ros.message_fields.uint8()
        Strategy to generate level value. (Default: Default hypothesis_ros strategy.)
    name : hypothesis_ros.message_fields.string()
        Strategy to generate name value. (Default: Default hypothesis_ros strategy.)
    msg : hypothesis_ros.message_fields.string()
        Strategy to generate msg value. (Default: Default hypothesis_ros strategy.)
    file : hypothesis_ros.message_fields.string()
        Strategy to generate file value. (Default: Default hypothesis_ros strategy.)
    function : hypothesis_ros.message_fields.string()
        Strategy to generate function value. (Default: Default hypothesis_ros strategy.)
    line : hypothesis_ros.message_fields.string()
        Strategy to generate line value. (Default: Default hypothesis_ros strategy.)
    topics : hypothesis_ros.message_fields.array()
        Strategy to generate topics value. (Default: Default hypothesis_ros strategy.)

    """

    header_value = draw(header)
    level_value = draw(level)
    name_value = draw(name)
    msg_value = draw(msg)
    file_value = draw(file)
    function_value = draw(function)
    line_value = draw(line)
    topics_value = draw(topics)

    assert isinstance(
        level_value, int
    ), 'drew invalid level={level_value} from {level} for int field'.format(
        level_value, level)
    assert isinstance(
        name_value, str
    ), 'drew invalid name={name_value} from {name} for string field'.format(
        name_value, name)
    assert isinstance(
        msg_value, str
    ), 'drew invalid msg={msg_value} from {msg} for string field'.format(
        msg_value, msg)
    assert isinstance(
        file_value, str
    ), 'drew invalid file={file_value} from {file} for string field'.format(
        file_value, file)
    assert isinstance(
        function_value, str
    ), 'drew invalid function={function_value} from {function} for string field'.format(
        function_value, function)
    assert isinstance(
        line_value, int
    ), 'drew invalid line={line_value} from {line} for int field'.format(
        line_value, line)
    assert isinstance(
        topics_value, list
    ), 'drew invalid topics={topics_value} from {msg} for list field'.format(
        topics_value, topics)

    return _Log(header_value, level_value, name_value, msg_value, file_value,
                function_value, line_value, topics_value)
コード例 #7
0
    camera_info,
)
from hypothesis_ros.messages.geometry_msgs import vector3, quaternion
from hypothesis_ros.messages.std_msgs import header
from hypothesis_ros.message_fields import (
    array,
    bool,
    float32,
    float64,
    time,
    uint8,
    uint32,
)


@given(region_of_interest(x_offset=uint32(min_value=1, max_value=1),
                          y_offset=uint32(min_value=2, max_value=2),
                          height=uint32(min_value=3, max_value=3),
                          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)
                            ),
コード例 #8
0
Unit tests for the stereo_msgs strategies.
"""

from hypothesis import given
from hypothesis.strategies import just

from hypothesis_ros.messages.stereo_msgs import disparity_image
from hypothesis_ros.messages.geometry_msgs import transform_stamped
from hypothesis_ros.messages.sensor_msgs import image, region_of_interest
from hypothesis_ros.messages.std_msgs import header
from hypothesis_ros.message_fields import (array, float32, uint8, uint32, time)


@given(
    disparity_image(
        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')),
        image(
            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')),
            uint32(min_value=1, max_value=1), uint32(min_value=2, max_value=2),
            just('rgb8'), uint32(min_value=3, max_value=3),
            uint8(min_value=4, max_value=4),
            array(elements=uint8(min_value=0, max_value=0),
                  min_size=4,
                  max_size=4)), float32(min_value=1.0, max_value=1.0),
        float32(min_value=2.0, max_value=2.0),
コード例 #9
0
def test_uint32_with_invalid_min_value_raises_exception():
    """Verifies validation of Uint32 min_value (lower limit)."""
    with raises(InvalidArgument):
        uint32(min_value=UINT32_MIN_VALUE - 1).example()
コード例 #10
0

@given(int32())
def test_int32_generates_in_range_value_per_default(generated_value):
    """Verify default value range for Int32."""
    assert generated_value >= INT32_MIN_VALUE
    assert generated_value <= INT32_MAX_VALUE


def test_int32_with_invalid_min_value_raises_exception():
    """Verifies validation of Int32 min_value (lower limit)."""
    with raises(InvalidArgument):
        int32(min_value=INT32_MIN_VALUE - 1).example()


@given(uint32())
def test_uint32_generates_in_range_value_per_default(generated_value):
    """Verify default value range for Uint32."""
    assert generated_value >= UINT32_MIN_VALUE
    assert generated_value <= UINT32_MAX_VALUE


def test_uint32_with_invalid_min_value_raises_exception():
    """Verifies validation of Uint32 min_value (lower limit)."""
    with raises(InvalidArgument):
        uint32(min_value=UINT32_MIN_VALUE - 1).example()


@given(int64())
def test_int64_generates_in_range_value_per_default(generated_value):
    """Verify default value range for Int64."""
コード例 #11
0
    """Exemplary customized pose_with_covariance."""
    assert generated_value == (((1.0, 2.0, 3.0),
                                (1.0, 2.0, 3.0, 4.0)
                               ),
                               [0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                                0.0, 0.0, 0.0, 0.0, 0.0, 0.0
                               ]
                              )


@given(pose_with_covariance_stamped(
           header(seq=uint32(min_value=0, max_value=0),
                  stamp=time(
                      secs=uint32(min_value=0, max_value=0),
                      nsecs=uint32(min_value=0, max_value=0)
                  ),
                  frame_id=just('some_tf_frame_name')
                 ),
           pose_with_covariance(pose(position=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)
                                                   ),
                                     orientation=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)
                                                           )
コード例 #12
0
# -*- coding: utf-8 -*-
"""
Unit tests for the std_msgs strategies.
"""

from hypothesis import given
from hypothesis.strategies import just
from hypothesis_ros.messages.std_msgs import (
    header,
)
from hypothesis_ros.message_fields import (
    uint32,
    time,
)


@given(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')
             )
      )
def test_header_accepts_customized_strategies(generated_value):
    """Exemplary customized header."""
    assert generated_value == (0, (1, 2), 'some_tf_frame_name')