Skip to content

Commit eba962d

Browse files
Add pytest for example1 description (ros-controls#342)
1 parent 319b555 commit eba962d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1678
-13
lines changed

example_1/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ install(TARGETS ros2_control_demo_example_1
6464
)
6565

6666
if(BUILD_TESTING)
67-
find_package(ament_cmake_gtest REQUIRED)
67+
find_package(ament_cmake_pytest REQUIRED)
68+
69+
ament_add_pytest_test(example_1_urdf_xacro test/test_urdf_xacro.py)
70+
ament_add_pytest_test(view_example_1_launch test/test_view_robot_launch.py)
6871
endif()
6972

73+
7074
## EXPORTS
7175
ament_export_targets(export_ros2_control_demo_example_1 HAS_LIBRARY_TARGET)
7276
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})

example_1/package.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
<exec_depend>rviz2</exec_depend>
3434
<exec_depend>xacro</exec_depend>
3535

36-
<test_depend>ament_cmake_gtest</test_depend>
36+
<test_depend>ament_cmake_pytest</test_depend>
37+
<test_depend>launch_testing_ament_cmake</test_depend>
38+
<test_depend>launch_testing_ros</test_depend>
39+
<test_depend>liburdfdom-tools</test_depend>
40+
<test_depend>xacro</test_depend>
3741

3842
<export>
3943
<build_type>ament_cmake</build_type>

example_1/test/test_urdf_xacro.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (c) 2022 FZI Forschungszentrum Informatik
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
#
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# * Neither the name of the {copyright_holder} nor the names of its
14+
# contributors may be used to endorse or promote products derived from
15+
# this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Author: Lukas Sackewitz
30+
31+
import os
32+
import shutil
33+
import subprocess
34+
import tempfile
35+
36+
from ament_index_python.packages import get_package_share_directory
37+
38+
39+
def test_urdf_xacro():
40+
# General Arguments
41+
description_package = "ros2_control_demo_example_1"
42+
description_file = "rrbot.urdf.xacro"
43+
44+
description_file_path = os.path.join(
45+
get_package_share_directory(description_package), "urdf", description_file
46+
)
47+
48+
(_, tmp_urdf_output_file) = tempfile.mkstemp(suffix=".urdf")
49+
50+
# Compose `xacro` and `check_urdf` command
51+
xacro_command = (
52+
f"{shutil.which('xacro')}" f" {description_file_path}" f" > {tmp_urdf_output_file}"
53+
)
54+
check_urdf_command = f"{shutil.which('check_urdf')} {tmp_urdf_output_file}"
55+
56+
# Try to call processes but finally remove the temp file
57+
try:
58+
xacro_process = subprocess.run(
59+
xacro_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
60+
)
61+
62+
assert xacro_process.returncode == 0, " --- XACRO command failed ---"
63+
64+
check_urdf_process = subprocess.run(
65+
check_urdf_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
66+
)
67+
68+
assert (
69+
check_urdf_process.returncode == 0
70+
), "\n --- URDF check failed! --- \nYour xacro does not unfold into a proper urdf robot description. Please check your xacro file."
71+
72+
finally:
73+
os.remove(tmp_urdf_output_file)
74+
75+
76+
if __name__ == "__main__":
77+
test_urdf_xacro()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2022 FZI Forschungszentrum Informatik
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
#
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# * Neither the name of the {copyright_holder} nor the names of its
14+
# contributors may be used to endorse or promote products derived from
15+
# this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Author: Lukas Sackewitz
30+
31+
import os
32+
import pytest
33+
34+
from ament_index_python.packages import get_package_share_directory
35+
from launch import LaunchDescription
36+
from launch.actions import IncludeLaunchDescription
37+
from launch.launch_description_sources import PythonLaunchDescriptionSource
38+
from launch_testing.actions import ReadyToTest
39+
40+
41+
# Executes the given launch file and checks if all nodes can be started
42+
@pytest.mark.rostest
43+
def generate_test_description():
44+
launch_include = IncludeLaunchDescription(
45+
PythonLaunchDescriptionSource(
46+
os.path.join(
47+
get_package_share_directory("ros2_control_demo_example_1"),
48+
"launch/view_robot.launch.py",
49+
)
50+
),
51+
launch_arguments={"gui": "true"}.items(),
52+
)
53+
54+
return LaunchDescription([launch_include, ReadyToTest()])

example_10/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ install(TARGETS ros2_control_demo_example_10
7575
)
7676

7777
if(BUILD_TESTING)
78-
find_package(ament_cmake_gtest REQUIRED)
78+
find_package(ament_cmake_pytest REQUIRED)
79+
80+
ament_add_pytest_test(example_10_urdf_xacro test/test_urdf_xacro.py)
81+
ament_add_pytest_test(view_example_10_launch test/test_view_robot_launch.py)
7982
endif()
8083

8184
## EXPORTS

example_10/package.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
<exec_depend>xacro</exec_depend>
3434

3535
<test_depend>ament_cmake_gtest</test_depend>
36+
<test_depend>ament_cmake_pytest</test_depend>
37+
<test_depend>launch_testing_ament_cmake</test_depend>
38+
<test_depend>launch_testing_ros</test_depend>
39+
<test_depend>liburdfdom-tools</test_depend>
40+
<test_depend>xacro</test_depend>
3641

3742
<export>
3843
<build_type>ament_cmake</build_type>

example_10/test/test_urdf_xacro.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright (c) 2022 FZI Forschungszentrum Informatik
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
#
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# * Neither the name of the {copyright_holder} nor the names of its
14+
# contributors may be used to endorse or promote products derived from
15+
# this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Author: Lukas Sackewitz
30+
31+
import os
32+
import shutil
33+
import subprocess
34+
import tempfile
35+
36+
from ament_index_python.packages import get_package_share_directory
37+
38+
39+
def test_urdf_xacro():
40+
# General Arguments
41+
description_package = "ros2_control_demo_example_10"
42+
description_file = "rrbot.urdf.xacro"
43+
44+
description_file_path = os.path.join(
45+
get_package_share_directory(description_package), "urdf", description_file
46+
)
47+
48+
(_, tmp_urdf_output_file) = tempfile.mkstemp(suffix=".urdf")
49+
50+
# Compose `xacro` and `check_urdf` command
51+
xacro_command = (
52+
f"{shutil.which('xacro')}" f" {description_file_path}" f" > {tmp_urdf_output_file}"
53+
)
54+
check_urdf_command = f"{shutil.which('check_urdf')} {tmp_urdf_output_file}"
55+
56+
# Try to call processes but finally remove the temp file
57+
try:
58+
xacro_process = subprocess.run(
59+
xacro_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
60+
)
61+
62+
assert xacro_process.returncode == 0, " --- XACRO command failed ---"
63+
64+
check_urdf_process = subprocess.run(
65+
check_urdf_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
66+
)
67+
68+
assert (
69+
check_urdf_process.returncode == 0
70+
), "\n --- URDF check failed! --- \nYour xacro does not unfold into a proper urdf robot description. Please check your xacro file."
71+
72+
finally:
73+
os.remove(tmp_urdf_output_file)
74+
75+
76+
if __name__ == "__main__":
77+
test_urdf_xacro()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) 2022 FZI Forschungszentrum Informatik
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright
7+
# notice, this list of conditions and the following disclaimer.
8+
#
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# * Neither the name of the {copyright_holder} nor the names of its
14+
# contributors may be used to endorse or promote products derived from
15+
# this software without specific prior written permission.
16+
#
17+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
# POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# Author: Lukas Sackewitz
30+
31+
import os
32+
import pytest
33+
34+
from ament_index_python.packages import get_package_share_directory
35+
from launch import LaunchDescription
36+
from launch.actions import IncludeLaunchDescription
37+
from launch.launch_description_sources import PythonLaunchDescriptionSource
38+
from launch_testing.actions import ReadyToTest
39+
40+
41+
# Executes the given launch file and checks if all nodes can be started
42+
@pytest.mark.rostest
43+
def generate_test_description():
44+
launch_include = IncludeLaunchDescription(
45+
PythonLaunchDescriptionSource(
46+
os.path.join(
47+
get_package_share_directory("ros2_control_demo_example_10"),
48+
"launch/view_robot.launch.py",
49+
)
50+
),
51+
launch_arguments={"gui": "true"}.items(),
52+
)
53+
54+
return LaunchDescription([launch_include, ReadyToTest()])

example_12/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ install(TARGETS
105105
)
106106

107107
if(BUILD_TESTING)
108-
find_package(ament_cmake_gtest REQUIRED)
108+
find_package(ament_cmake_pytest REQUIRED)
109+
110+
ament_add_pytest_test(example_12_urdf_xacro test/test_urdf_xacro.py)
111+
ament_add_pytest_test(view_example_12_launch test/test_view_robot_launch.py)
109112
endif()
110113

111114
## EXPORTS

example_12/package.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@
2929
<exec_depend>joint_state_publisher_gui</exec_depend>
3030
<exec_depend>joint_trajectory_controller</exec_depend>
3131
<exec_depend>robot_state_publisher</exec_depend>
32+
<exec_depend>ros2_control_demo_description</exec_depend>
3233
<exec_depend>ros2_controllers_test_nodes</exec_depend>
3334
<exec_depend>ros2controlcli</exec_depend>
3435
<exec_depend>rviz2</exec_depend>
3536
<exec_depend>xacro</exec_depend>
3637

3738
<test_depend>ament_cmake_gtest</test_depend>
39+
<test_depend>ament_cmake_pytest</test_depend>
40+
<test_depend>launch_testing_ament_cmake</test_depend>
41+
<test_depend>launch_testing_ros</test_depend>
42+
<test_depend>liburdfdom-tools</test_depend>
43+
<test_depend>xacro</test_depend>
3844

3945
<export>
4046
<build_type>ament_cmake</build_type>

0 commit comments

Comments
 (0)