Skip to content

Commit

Permalink
add WString tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
  • Loading branch information
dirk-thomas committed May 2, 2019
1 parent cc07f9d commit bcfd1cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions rosidl_generator_py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if(BUILD_TESTING)
#"msg/Uint64.msg"
#"msg/Uint8.msg"
"msg/Various.msg"
"msg/WStrings.msg"
)

include(cmake/register_py.cmake)
Expand Down
23 changes: 23 additions & 0 deletions rosidl_generator_py/test/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from rosidl_generator_py.msg import StringArrays
from rosidl_generator_py.msg import Strings
from rosidl_generator_py.msg import Various
from rosidl_generator_py.msg import WStrings


def test_strings():
Expand All @@ -31,6 +32,13 @@ def test_strings():
assert 'Hello world!' == a.def_string


def test_wstrings():
a = WStrings()

assert '' == a.empty_wstring
assert 'Hello world!' == a.def_wstring


def test_arrays_of_bounded_strings():
a = StringArrays()
array_valid_string_length = ['a' * 2, 'b' * 3, 'c' * 4]
Expand Down Expand Up @@ -123,6 +131,21 @@ def test_default_values():
with pytest.raises(AttributeError):
setattr(Strings, 'DEF_STRING__DEFAULT', 'bar')

a = WStrings()
assert '' == a.empty_wstring
assert 'Hello world!' == a.def_wstring
a.def_wstring = 'Bye world'
assert 'Bye world' == a.def_wstring
assert 'Hello world!' == WStrings.DEF_WSTRING__DEFAULT
assert 'Hello world!' == a.DEF_WSTRING__DEFAULT

assert "Hello'world!" == a.DEF_WSTRING2__DEFAULT
assert 'Hello"world!' == a.DEF_WSTRING3__DEFAULT
assert "Hello'world!" == a.DEF_WSTRING4__DEFAULT
assert 'Hello"world!' == a.DEF_WSTRING5__DEFAULT
with pytest.raises(AttributeError):
setattr(WStrings, 'DEF_WSTRING__DEFAULT', 'bar')

b = StringArrays()
assert ['What', 'a', 'wonderful', 'world', '!'] == b.DEF_STRING_DYNAMIC_ARRAY_VALUE__DEFAULT
assert ['Hello', 'World', '!'] == b.DEF_STRING_STATIC_ARRAY_VALUE__DEFAULT
Expand Down

0 comments on commit bcfd1cb

Please sign in to comment.