Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly map byte[] AKA IDL type sequence<octet> to Python type bytes #142

Draft
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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