Skip to content

Commit

Permalink
Add ros_testing metapackage and ros2test CLI package (#1)
Browse files Browse the repository at this point in the history
* Add ros2 test CLI command.

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

* Add ros2 testing metapackage.

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

* Add add_ros_test() CMake convenience macro.

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

* Apply minor fixes to ros2 test CLI command.

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

* Drop ROS2 specific naming.

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

* Apply misc fixes to the ros_testing package.

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

* Apply misc fixes to the ros2test package.

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

* Change ros2test and ros_testing versions.

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic authored May 17, 2019
1 parent d81b282 commit c69c48e
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ros2test/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model
href="http://download.ros.org/schema/package_format2.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ros2test</name>
<version>0.1.0</version>
<description>The test command for ROS 2 launch tests.</description>
<maintainer email="michel@ekumenlabs.com">Michel Hidalgo</maintainer>
<license>Apache License 2.0</license>

<depend>launch</depend>
<depend>launch_ros</depend>
<depend>launch_testing</depend>
<depend>launch_testing_ros</depend>
<depend>ros2cli</depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file added ros2test/ros2test/__init__.py
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions ros2test/ros2test/command/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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.

import launch_testing.launch_test
import launch_testing_ros

from ros2cli.command import CommandExtension


class TestCommand(CommandExtension):
"""Run a ROS2 launch test."""

def add_arguments(self, parser, cli_name):
"""Add arguments to argparse."""
launch_testing.launch_test.add_arguments(parser)

def main(self, *, parser, args):
"""Entry point for CLI program."""
return launch_testing.launch_test.run(
parser, args, test_runner_cls=launch_testing_ros.LaunchTestRunner
)
33 changes: 33 additions & 0 deletions ros2test/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from setuptools import find_packages
from setuptools import setup

setup(
name='ros2test',
version='0.1.0',
packages=find_packages(exclude=['test']),
install_requires=['ros2cli'],
zip_safe=True,
author='Michel Hidalgo',
author_email='michel@ekumenlabs.com',
maintainer='Michel Hidalgo',
maintainer_email='michel@ekumenlabs.com',
url='https://github.com/ros2/rostest/tree/master/ros2test',
download_url='https://github.com/ros2/rostest/releases',
keywords=[],
classifiers=[
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
],
description='The test command for ROS 2 launch tests.',
long_description="""\
This package provides the test command for ROS 2 launch tests.""",
license='Apache License, Version 2.0',
tests_require=['pytest'],
entry_points={
'ros2cli.command': [
'test = ros2test.command.test:TestCommand',
],
}
)
23 changes: 23 additions & 0 deletions ros2test/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2017 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 ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
23 changes: 23 additions & 0 deletions ros2test/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2017 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 ament_flake8.main import main
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc = main(argv=[])
assert rc == 0, 'Found errors'
23 changes: 23 additions & 0 deletions ros2test/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2017 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 ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=[])
assert rc == 0, 'Found code style errors / warnings'
14 changes: 14 additions & 0 deletions ros_testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.5)

project(ros_testing NONE)

find_package(ament_cmake_core REQUIRED)

ament_package(
CONFIG_EXTRAS "${PROJECT_NAME}-extras.cmake"
)

install(
DIRECTORY cmake
DESTINATION share/${PROJECT_NAME}
)
81 changes: 81 additions & 0 deletions ros_testing/cmake/add_ros_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 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.

# This file contains modified code from the following open source projects
# published under the licenses listed below:

# Software License Agreement (BSD License)
#
# Copyright (c) 2008, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

#
# Add a ROS test
#
# :param file: The ROS launch test file containing the test to run
# :type file: string
# :param TARGET: The test target name
# :type TARGET: string
# :param TIMEOUT: The test timeout in seconds
# :type TIMEOUT: integer
# :param ARGS: Launch arguments to pass to the ROS launch test
# :type ARGS: string
function(add_ros_test filename)
parse_launch_test_arguments(_ros_test ${filename} ${ARGN})

set(cmd
"ros2"
"test"
"${_ros_test_FILE_NAME}"
"${_ros_test_ARGS}"
"--junit-xml=${_ros_test_RESULT_FILE}"
"--package-name=${PROJECT_NAME}"
)

ament_add_test(
"${_ros_test_TARGET}"
COMMAND ${cmd}
OUTPUT_FILE "${CMAKE_BINARY_DIR}/ros_test/CHANGEME.txt"
RESULT_FILE "${_ros_test_RESULT_FILE}"
TIMEOUT "${_ros_test_TIMEOUT}"
${_ros_test_UNPARSED_ARGUMENTS}
)
endfunction()
30 changes: 30 additions & 0 deletions ros_testing/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ros_testing</name>
<version>0.1.0</version>
<description>The entry point package to launch testing in ROS.</description>
<maintainer email="michel@ekumenlabs.com">Michel Hidalgo</maintainer>
<license>Apache License 2.0</license>

<author email="michel@ekumenlabs.com">Michel Hidalgo</author>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_export_depend>launch_testing_ament_cmake</buildtool_export_depend>
<buildtool_export_depend>ros2test</buildtool_export_depend>

<build_depend>ament_cmake_core</build_depend>
<build_depend>ament_cmake_export_dependencies</build_depend>

<build_export_depend>launch_testing</build_export_depend>
<build_export_depend>launch_testing_ros</build_export_depend>
<build_export_depend>launch_testing_ament_cmake</build_export_depend>

<exec_depend>launch_testing</exec_depend>
<exec_depend>launch_testing_ros</exec_depend>
<exec_depend>ros2test</exec_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
17 changes: 17 additions & 0 deletions ros_testing/ros_testing-extras.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.

find_package(launch_testing_ament_cmake REQUIRED)

include("${ros_testing_DIR}/add_ros_test.cmake")

0 comments on commit c69c48e

Please sign in to comment.