Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def compressed_image(draw,
                     header=header(),
                     format=sampled_from(['jpg', 'png']),
                     data=array(elements=uint8())):
    """
    Generate values for ROS1 sensor_msgs/CompressedImage.msg.

    Parameters
    ----------
    header : hypothesis_ros.std_msgs.header()
        Strategy to generate header value. (Default: Default hypothesis_ros strategy.)
    format : hypothesis.strategies.sampled_from()
        Strategy to generate format value. (Default: Customized hypothesis strategy.)
    data : hypothesis_ros.message_fields.array()
        Strategy to generate format value. (Default: Customized to elements of type uint8().)

    """
    header_value = draw(header)
    format_value = draw(format)
    data_value = draw(data)
    return _CompressedImage(header_value, format_value, data_value)
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)
                                (1.0, 2.0, 3.0, 4.0),
                                [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
                                (1.0, 2.0, 3.0),
                                [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0],
                                (1.0, 2.0, 3.0),
                                [3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0])


@given(compressed_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')
                              ),
                        just('jpg'),
                        array(elements=uint8(min_value=0, max_value=0), min_size=4, max_size=4)
                       )
      )
def test_compressed_image_accepts_customized_strategies(generated_values):
    """Exemplary customized compressed_image message fields."""
    assert generated_values == ((0, (1, 2), 'some_tf_frame_name'),
                                'jpg',
                                [0, 0,
                                 0, 0])


@given(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')
def test_uint8_with_invalid_min_value_raises_exception():
    """Verifies validation of int8 min_value (lower limit)."""
    with raises(InvalidArgument):
        uint8(min_value=UINT8_MIN_VALUE - 1).example()

def test_int8_with_invalid_max_value_raises_exception():
    """Verifies validation of int8 max_value (upper limit)."""
    with raises(InvalidArgument):
        int8(max_value=INT8_MAX_VALUE + 1).example()


def test_int8_with_bigger_min_than_max_value_raises_exception():
    """Verifies validation of int8 min_value/max_value."""
    in_range_value = INT8_MAX_VALUE / 2
    with raises(InvalidArgument):
        int8(min_value=in_range_value + 1, max_value=in_range_value).example()


@given(uint8())
def test_uint8_generates_expected_max_value_as_default(generated_value):
    """Verify default value range for Uint8."""
    assert generated_value >= UINT8_MIN_VALUE
    assert generated_value <= UINT8_MAX_VALUE


def test_uint8_with_invalid_min_value_raises_exception():
    """Verifies validation of int8 min_value (lower limit)."""
    with raises(InvalidArgument):
        uint8(min_value=UINT8_MIN_VALUE - 1).example()


@given(int16())
def test_int16_generates_expected_max_value_as_default(generated_value):
    """Verify default value range for Int16."""