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

Support launch_ros test runner in pytest #54

Merged
merged 7 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions launch_testing_ros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# launch\_testing\_ros

## Examples

### `talker_listener_launch_test.py`

Usage:

```sh
launch_test test/examples/talker_listener_launch_test.py
```

This test launches the talker and listener example nodes from demo\_nodes\_py and interacts
with them via their ROS interfaces. Remapping rules are used so that one of the tests can sit in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New sentence should start on new line.

Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. It predates the PR but you're right.

between the talker and the listener and change the data on the fly.

#### test\_fuzzy\_data
This test gives an example of what a test that fuzzes data might look like. A ROS subscriber
and publisher pair encapsulated in a `DataRepublisher` object changes the string "Hello World" to
"Aloha World" as it travels between the talker and the listener.

#### test\_listener\_receives
This test publishes unique messages on the `/chatter` topic and asserts that the same messages
go to the stdout of the listener node

#### test\_talker\_transmits
This test subscribes to the remapped `/talker_chatter` topic and makes sure the talker node also
writes the data it's transmitting to stdout
31 changes: 0 additions & 31 deletions launch_testing_ros/examples/README.md

This file was deleted.

195 changes: 0 additions & 195 deletions launch_testing_ros/examples/talker_listener.test.py

This file was deleted.

Empty file.
43 changes: 43 additions & 0 deletions launch_testing_ros/launch_testing_ros/pytest/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from launch_testing.pytest.hooks import LaunchTestItem
from launch_testing.pytest.hooks import LaunchTestModule

from ..test_runner import LaunchTestRunner


class LaunchROSTestItem(LaunchTestItem):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, runner_cls=LaunchTestRunner)


class LaunchROSTestModule(LaunchTestModule):

def makeitem(self, *args, **kwargs):
return LaunchROSTestItem(*args, **kwargs)


def pytest_launch_collect_makemodule(path, parent, entrypoint):
marks = getattr(entrypoint, 'pytestmark', [])
if marks and any(m.name == 'rostest' for m in marks):
return LaunchROSTestModule(path, parent)


def pytest_configure(config):
config.addinivalue_line(
'markers',
'rostest: mark a generate_test_description function as a ROS launch test entrypoint'
)
5 changes: 4 additions & 1 deletion launch_testing_ros/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
data_files=[
('share/ament_index/resource_index/packages', ['resource/launch_testing_ros']),
('lib/launch_testing_ros', glob.glob('example_nodes/**')),
('share/launch_testing_ros/examples', glob.glob('examples/[!_]**')),
('share/launch_testing_ros/examples', glob.glob('test/examples/[!_]**')),
],
entry_points={
'pytest11': ['launch_ros = launch_testing_ros.pytest.hooks'],
},
install_requires=['setuptools'],
zip_safe=True,
author='Pete Baughman',
Expand Down
Loading