Skip to content

Commit

Permalink
Drops legacy launch API usage.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Feb 11, 2019
1 parent 6d348de commit 01e50e7
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 367 deletions.
51 changes: 27 additions & 24 deletions composition/test/test_api_pubsub_composition.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from launch.legacy import LaunchDescriptor
from launch.legacy.exit_handler import default_exit_handler
from launch.legacy.exit_handler import exit_on_error_exit_handler
from launch.legacy.launcher import DefaultLauncher
from launch.legacy.output_handler import ConsoleOutput
from launch_testing import create_handler
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch_testing import LaunchTestService
from launch_testing.output import create_output_lines_filter
from launch_testing.output import create_output_test_from_file


def test_api_pubsub_composition():
Expand All @@ -29,47 +29,50 @@ def test_api_pubsub_composition():
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Talker'],
'name': 'load_talker_component',
'exit_handler': exit_on_error_exit_handler,
},
{
'cmd': [
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Listener'],
'name': 'load_listener_component',
'exit_handler': exit_on_error_exit_handler,
}
]
output_file = '@EXPECTED_OUTPUT_PUBSUB@'
launch(name, [executable], output_file, additional_processes=additional_processes)


def launch(name, cmd, output_file, additional_processes=None):
launch_descriptor = LaunchDescriptor()
launch_test = LaunchTestService()
launch_description = LaunchDescription()

action = launch_test.add_fixture_action(
launch_description, ExecuteProcess(
cmd=cmd,
name=name,
output='screen'
)
)
rmw_implementation = '@rmw_implementation@'
handler = create_handler(
name, launch_descriptor, output_file,
filtered_rmw_implementation=rmw_implementation)
assert handler, 'Cannot find appropriate handler for %s' % output_file
launch_descriptor.add_process(
cmd=cmd,
name=name,
exit_handler=default_exit_handler,
output_handlers=[ConsoleOutput(), handler],
launch_test.add_output_test(
launch_description, action,
output_test=create_output_test_from_file(output_file),
output_filter=create_output_lines_filter(
filtered_rmw_implementation=rmw_implementation
)
)
for additional_process in (additional_processes or []):
launch_descriptor.add_process(**additional_process)
launch_test.add_fixture_action(
launch_description, ExecuteProcess(**additional_process)
)

launcher = DefaultLauncher()
launcher.add_launch_descriptor(launch_descriptor)
rc = launcher.launch()
launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
rc = launch_test.run(launch_service)

assert rc == 0, \
"The launch file failed with exit code '" + str(rc) + "'. " \
'Maybe the client did not receive any messages?'

handler.check()


if __name__ == '__main__':
test_api_pubsub_composition()
51 changes: 27 additions & 24 deletions composition/test/test_api_srv_composition.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from launch.legacy import LaunchDescriptor
from launch.legacy.exit_handler import default_exit_handler
from launch.legacy.exit_handler import exit_on_error_exit_handler
from launch.legacy.launcher import DefaultLauncher
from launch.legacy.output_handler import ConsoleOutput
from launch_testing import create_handler
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch_testing import LaunchTestService
from launch_testing.output import create_output_lines_filter
from launch_testing.output import create_output_test_from_file


def test_api_srv_composition():
Expand All @@ -29,47 +29,50 @@ def test_api_srv_composition():
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Server'],
'name': 'load_server_component',
'exit_handler': exit_on_error_exit_handler,
},
{
'cmd': [
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Client'],
'name': 'load_client_component',
'exit_handler': exit_on_error_exit_handler,
},
]
output_file = '@EXPECTED_OUTPUT_SRV@'
launch(name, [executable], output_file, additional_processes=additional_processes)


def launch(name, cmd, output_file, additional_processes=None):
launch_descriptor = LaunchDescriptor()
launch_test = LaunchTestService()
launch_description = LaunchDescription()

action = launch_test.add_fixture_action(
launch_description, ExecuteProcess(
cmd=cmd,
name=name,
output='screen'
)
)
rmw_implementation = '@rmw_implementation@'
handler = create_handler(
name, launch_descriptor, output_file,
filtered_rmw_implementation=rmw_implementation)
assert handler, 'Cannot find appropriate handler for %s' % output_file
launch_descriptor.add_process(
cmd=cmd,
name=name,
exit_handler=default_exit_handler,
output_handlers=[ConsoleOutput(), handler],
launch_test.add_output_test(
launch_description, action,
output_test=create_output_test_from_file(output_file),
output_filter=create_output_lines_filter(
filtered_rmw_implementation=rmw_implementation
)
)
for additional_process in (additional_processes or []):
launch_descriptor.add_process(**additional_process)
launch_test.add_fixture_action(
launch_description, ExecuteProcess(**additional_process)
)

launcher = DefaultLauncher()
launcher.add_launch_descriptor(launch_descriptor)
rc = launcher.launch()
launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
rc = launch_test.run(launch_service)

assert rc == 0, \
"The launch file failed with exit code '" + str(rc) + "'. " \
'Maybe the client did not receive any messages?'

handler.check()


if __name__ == '__main__':
test_api_srv_composition()
51 changes: 27 additions & 24 deletions composition/test/test_api_srv_composition_client_first.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from launch.legacy import LaunchDescriptor
from launch.legacy.exit_handler import default_exit_handler
from launch.legacy.exit_handler import exit_on_error_exit_handler
from launch.legacy.launcher import DefaultLauncher
from launch.legacy.output_handler import ConsoleOutput
from launch_testing import create_handler
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch_testing import LaunchTestService
from launch_testing.output import create_output_lines_filter
from launch_testing.output import create_output_test_from_file


def test_api_srv_composition_client_first():
Expand All @@ -31,47 +31,50 @@ def test_api_srv_composition_client_first():
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Client'],
'name': 'load_client_component',
'exit_handler': exit_on_error_exit_handler,
},
{
'cmd': [
'@API_COMPOSITION_CLI_EXECUTABLE@',
'composition', 'composition::Server', '--delay', '5000'],
'name': 'load_server_component',
'exit_handler': exit_on_error_exit_handler,
},
]
output_file = '@EXPECTED_OUTPUT_SRV@'
launch(name, [executable], output_file, additional_processes=additional_processes)


def launch(name, cmd, output_file, additional_processes=None):
launch_descriptor = LaunchDescriptor()
launch_test = LaunchTestService()
launch_description = LaunchDescription()

action = launch_test.add_fixture_action(
launch_description, ExecuteProcess(
cmd=cmd,
name=name,
output='screen'
)
)
rmw_implementation = '@rmw_implementation@'
handler = create_handler(
name, launch_descriptor, output_file,
filtered_rmw_implementation=rmw_implementation)
assert handler, 'Cannot find appropriate handler for %s' % output_file
launch_descriptor.add_process(
cmd=cmd,
name=name,
exit_handler=default_exit_handler,
output_handlers=[ConsoleOutput(), handler],
launch_test.add_output_test(
launch_description, action,
output_test=create_output_test_from_file(output_file),
output_filter=create_output_lines_filter(
filtered_rmw_implementation=rmw_implementation
)
)
for additional_process in (additional_processes or []):
launch_descriptor.add_process(**additional_process)
launch_test.add_fixture_action(
launch_description, ExecuteProcess(**additional_process)
)

launcher = DefaultLauncher()
launcher.add_launch_descriptor(launch_descriptor)
rc = launcher.launch()
launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
rc = launch_test.run(launch_service)

assert rc == 0, \
"The launch file failed with exit code '" + str(rc) + "'. " \
'Maybe the client did not receive any messages?'

handler.check()


if __name__ == '__main__':
test_api_srv_composition_client_first()
48 changes: 27 additions & 21 deletions composition/test/test_dlopen_composition.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from launch.legacy import LaunchDescriptor
from launch.legacy.exit_handler import default_exit_handler
from launch.legacy.launcher import DefaultLauncher
from launch.legacy.output_handler import ConsoleOutput
from launch_testing import create_handler
from launch import LaunchDescription
from launch import LaunchService
from launch.actions import ExecuteProcess
from launch_testing import LaunchTestService
from launch_testing.output import create_output_lines_filter
from launch_testing.output import create_output_test_from_file


def test_dlopen_composition():
Expand All @@ -34,32 +35,37 @@ def test_dlopen_composition():


def launch(name, cmd, output_file, additional_processes=None):
launch_descriptor = LaunchDescriptor()
launch_test = LaunchTestService()
launch_description = LaunchDescription()

action = launch_test.add_fixture_action(
launch_description, ExecuteProcess(
cmd=cmd,
name=name,
output='screen'
)
)
rmw_implementation = '@rmw_implementation@'
handler = create_handler(
name, launch_descriptor, output_file,
filtered_rmw_implementation=rmw_implementation)
assert handler, 'Cannot find appropriate handler for %s' % output_file
launch_descriptor.add_process(
cmd=cmd,
name=name,
exit_handler=default_exit_handler,
output_handlers=[ConsoleOutput(), handler],
launch_test.add_output_test(
launch_description, action,
output_test=create_output_test_from_file(output_file),
output_filter=create_output_lines_filter(
filtered_rmw_implementation=rmw_implementation
)
)
for additional_process in (additional_processes or []):
launch_descriptor.add_process(**additional_process)
launch_test.add_fixture_action(
launch_description, ExecuteProcess(**additional_process)
)

launcher = DefaultLauncher()
launcher.add_launch_descriptor(launch_descriptor)
rc = launcher.launch()
launch_service = LaunchService()
launch_service.include_launch_description(launch_description)
rc = launch_test.run(launch_service)

assert rc == 0, \
"The launch file failed with exit code '" + str(rc) + "'. " \
'Maybe the client did not receive any messages?'

handler.check()


if __name__ == '__main__':
test_dlopen_composition()
Loading

0 comments on commit 01e50e7

Please sign in to comment.