Skip to content

Commit

Permalink
Add correct IDL sequence<octet> mapping in tests
Browse files Browse the repository at this point in the history
The tests for `Arrays`, `BoundedSequences`, and `UnboundedSequences` are
modified to reflect the correct mapping from IDL type `sequence<octet>`
to Python type `bytes`, rather than Python type `list`.

Signed-off-by: aprotyas <aprotyas@u.rochester.edu>
  • Loading branch information
aprotyas committed Aug 27, 2021
1 parent f2727c1 commit 14969f2
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def test_arrays():

# types
assert isinstance(msg.bool_values, list)
assert isinstance(msg.byte_values, list)
assert isinstance(msg.byte_values, bytes)
# for legacy reasons, 'char' from a .msg interface maps to 'uint8'
assert isinstance(msg.char_values, numpy.ndarray)
assert isinstance(msg.float32_values, numpy.ndarray)
Expand Down Expand Up @@ -329,8 +329,9 @@ def test_arrays():
msg.bool_values = list_of_bool
assert list_of_bool == msg.bool_values
list_of_byte = [b'a', b'b', b'c']
msg.byte_values = list_of_byte
assert list_of_byte == msg.byte_values
bytes_instance = b'abc'
msg.byte_values = bytes_instance
assert bytes_instance == msg.byte_values
list_of_char = [0, 1, 255]
msg.char_values = list_of_char
assert numpy.array_equal(list_of_char, msg.char_values)
Expand Down Expand Up @@ -369,7 +370,7 @@ def test_arrays():
with pytest.raises(AssertionError):
msg.bool_values = [True]
with pytest.raises(AssertionError):
msg.byte_values = [b'd']
msg.byte_values = b'd'
with pytest.raises(AssertionError):
msg.char_values = [0]
with pytest.raises(AssertionError):
Expand Down Expand Up @@ -397,7 +398,7 @@ def test_arrays():
with pytest.raises(AssertionError):
msg.bool_values = ['not', 'a', 'bool']
with pytest.raises(AssertionError):
msg.byte_values = ['not', 'a', 'byte']
msg.byte_values = 'notabyte'
with pytest.raises(AssertionError):
msg.char_values = ['not', 'a', 'char']
with pytest.raises(AssertionError):
Expand Down Expand Up @@ -469,7 +470,7 @@ def test_bounded_sequences():

# types
assert isinstance(msg.bool_values, list)
assert isinstance(msg.byte_values, list)
assert isinstance(msg.byte_values, bytes)
# for legacy reasons, 'char' from a .msg interface maps to 'uint8'
assert isinstance(msg.char_values, array.array)
assert isinstance(msg.float32_values, array.array)
Expand All @@ -487,7 +488,7 @@ def test_bounded_sequences():

# defaults
assert [] == msg.bool_values
assert [] == msg.byte_values
assert b'' == msg.byte_values
assert array.array('B') == msg.char_values
assert array.array('f') == msg.float32_values
assert array.array('d') == msg.float64_values
Expand All @@ -508,11 +509,13 @@ def test_bounded_sequences():
msg.bool_values = short_list_of_bool
assert short_list_of_bool == msg.bool_values
list_of_byte = [b'a', b'b', b'c']
bytes_instance = b'abc'
short_list_of_byte = [b'd']
msg.byte_values = list_of_byte
assert list_of_byte == msg.byte_values
msg.byte_values = short_list_of_byte
assert short_list_of_byte == msg.byte_values
short_bytes_instance = b'd'
msg.byte_values = bytes_instance
assert bytes_instance == msg.byte_values
msg.byte_values = short_bytes_instance
assert short_bytes_instance == msg.byte_values
list_of_char = [0, 1, 255]
short_list_of_char = [0]
msg.char_values = list_of_char
Expand Down Expand Up @@ -584,7 +587,7 @@ def test_bounded_sequences():
with pytest.raises(AssertionError):
msg.bool_values = [True, False, True, False]
with pytest.raises(AssertionError):
msg.byte_values = [b'a', b'b', b'c', b'd']
msg.byte_values = b'abcd'
with pytest.raises(AssertionError):
msg.char_values = [1, 2, 3, 4]
with pytest.raises(AssertionError):
Expand Down Expand Up @@ -612,7 +615,7 @@ def test_bounded_sequences():
with pytest.raises(AssertionError):
msg.bool_values = ['not', 'a', 'bool']
with pytest.raises(AssertionError):
msg.byte_values = ['not', 'a', 'byte']
msg.byte_values = 'notabyte'
with pytest.raises(AssertionError):
msg.char_values = ['not', 'a', 'char']
with pytest.raises(AssertionError):
Expand Down Expand Up @@ -683,7 +686,7 @@ def test_unbounded_sequences():
msg = UnboundedSequences()

# types
assert isinstance(msg.byte_values, list)
assert isinstance(msg.byte_values, bytes)
# for legacy reasons, 'char' from a .msg interface maps to 'uint8'
assert isinstance(msg.char_values, array.array)
assert isinstance(msg.float32_values, array.array)
Expand All @@ -701,7 +704,7 @@ def test_unbounded_sequences():

# defaults
assert [] == msg.bool_values
assert [] == msg.byte_values
assert b'' == msg.byte_values
assert array.array('B') == msg.char_values
assert array.array('f') == msg.float32_values
assert array.array('d') == msg.float64_values
Expand All @@ -719,8 +722,9 @@ def test_unbounded_sequences():
msg.bool_values = list_of_bool
assert list_of_bool == msg.bool_values
list_of_byte = [b'a', b'b', b'c']
msg.byte_values = list_of_byte
assert list_of_byte == msg.byte_values
bytes_instance = b'abc'
msg.byte_values = bytes_instance
assert bytes_instance == msg.byte_values
list_of_char = [0, 1, 255]
msg.char_values = list_of_char
assert array.array('B', list_of_char) == msg.char_values
Expand Down Expand Up @@ -759,7 +763,7 @@ def test_unbounded_sequences():
with pytest.raises(AssertionError):
msg.bool_values = ['not', 'a', 'bool']
with pytest.raises(AssertionError):
msg.byte_values = ['not', 'a', 'byte']
msg.byte_values = 'notabyte'
with pytest.raises(AssertionError):
msg.char_values = ['not', 'a', 'char']
with pytest.raises(AssertionError):
Expand Down

0 comments on commit 14969f2

Please sign in to comment.