Skip to content

Commit

Permalink
Support launch_ros test runner in pytest (#54)
Browse files Browse the repository at this point in the history
* Support launch_ros test runner in pytest.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Test examples using pytest

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Improve pytest rostest marker documentation.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Move examples README to the root.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Remove single marker constraint for generate_test_description functions.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Please flake8

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>

* Install examples properly.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored Aug 23, 2019
1 parent 7e4f431 commit 413ad50
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 267 deletions.
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
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

0 comments on commit 413ad50

Please sign in to comment.