Skip to content
Open
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/
install/
log/
__pycache__/
*.py[codz]
67 changes: 67 additions & 0 deletions ament_cmake_python_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2025 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.

cmake_minimum_required(VERSION 3.12)

project(ament_cmake_python_test)

find_package(ament_cmake_core REQUIRED)

# Uncomment to debug CMake variables
#
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(ament_cmake_pytest REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(ament_cmake REQUIRED)
ament_get_python_install_dir(PYTHON_INSTALL_DIR)

set(_pytest_tests
test/test_packages.py
# Add other test files here
)

set(_env SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR})
list(APPEND _env PYTHON_INSTALL_DIR=${PYTHON_INSTALL_DIR})
list(APPEND _env PYEGG_VERSION=py${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR})
foreach(_test_path ${_pytest_tests})
get_filename_component(_test_name ${_test_path} NAME_WE)
ament_add_pytest_test(${_test_name} ${_test_path}
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
ENV ${_env}
TIMEOUT 360
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endforeach()

find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()

endif()
ament_package()
10 changes: 10 additions & 0 deletions ament_cmake_python_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ament_cmake_python_test

This package exists solely to test the ament_cmake_python package.

Packages to test are prepared as typical ros-style packages (e.g. with packages.xml). Some of these packages
exist in subdirectory `test/packages`, others are generated dynamically. The dynamically generated packages, as well
as the `build` and `install` subdirectories, are generated in a user's pytest temporary directories (which is typically
at /tmp/pytest-of-{username}/pytest-NN)

Testing can be initiated using normal ROS test commmands, that is `colcon test --packages-select ament_cmake_python_test`
34 changes: 34 additions & 0 deletions ament_cmake_python_test/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ament_cmake_python_test</name>
<version>0.0.1</version>
<description>Test package for ament_cmake_python.</description>

<maintainer email="[email protected]">Chris Lalancette</maintainer>
<license>Apache License 2.0</license>

<author email="[email protected]">R. Kent James</author>
<author email="[email protected]">Nadav Elkabets</author>

<buildtool_depend>ament_cmake_core</buildtool_depend>
<build_depend>ament_cmake_python</build_depend>
<build_depend>ament_cmake</build_depend>

<test_depend>python3-jinja2</test_depend>
<test_depend>rosidl_default_generators</test_depend>
<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_cmake_python</test_depend>
<test_depend>ament_cmake</test_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<test_depend>python3-pytest</test_depend>

<buildtool_export_depend>ament_cmake_core</buildtool_export_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
107 changes: 107 additions & 0 deletions ament_cmake_python_test/test/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Copyright 2025 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.

"""Options used to generate test packages from a template."""

# Set True to generate both a python package and a msg package for each python package
# This is useful to test that python and msg packages can coexist in the same package
# See issue #514 and PR #587
COMBINE_PYTHON_WITH_MSG = False

# Set True to test ordering sensitivity of python and msg generation in CMakeLists.txt
TEST_ORDERING_SENSITIVITY = False

DEFAULT_OPTIONS = {
'name': 'SET_ME',
'version': None,
'description': 'SET_ME',
'setup_cfg': None,
'destination': None,
'symlink_install': False,
'python_subdir': None,
'has_python': True,
'has_python_before': False, # if both python and msg are in the same package
'has_msg': False,
'scripts_destination': None,
}

TESTS_OPTIONS = [
{
'name': 'python_package',
'description': 'Package with python code',
},
{
'name': 'msg_package',
'description': 'Package with only msg files',
'has_msg': True,
'has_python': False,
},
{
'name': 'python_package_symlink',
'description': 'Package with python code, installed with symlink in build',
'symlink_install': True,
},
{
'name': 'python_package_rename',
'description': 'Package with python code, installed from alternate directory name',
'python_subdir': 'renamed_dir',
},
{
'name': 'python_package_version',
'description': 'Package with python code, specifying version',
'version': '6.7.89',
},
{
'name': 'python_package_setup',
'description': 'Package with python code, using setup.cfg for metadata',
'setup_cfg': 'config/setup.cfg',
},
{
'name': 'python_package_destination',
'description': 'Package with python code, installed to alternate destination',
'destination': 'new_destination',
},
{
'name': 'python_package_with_scripts',
'description': 'Package with python code',
'scripts_destination': 'lib/python_package_with_scripts',
},
]


def get_options():
"""Return a list of options dictionaries for generating test packages."""
tests_options = []
for options in TESTS_OPTIONS:
options = DEFAULT_OPTIONS | options
tests_options.append(options)

if COMBINE_PYTHON_WITH_MSG:
if options['name'].startswith('python_package'):
msg_options = options.copy()
msg_options['name'] += '_with_msg'
msg_options['description'] += 'and msg files'
msg_options['has_msg'] = True
tests_options.append(msg_options)

# This only makes sense when both python and msg are in the same package
if TEST_ORDERING_SENSITIVITY:
if options['name'].startswith('msg_package'):
py_options = options.copy()
py_options['name'] += '_with_python_before'
py_options['description'] += ' and python code before msg'
py_options['has_python_before'] = True
tests_options.append(py_options)

return tests_options
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2025 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.

cmake_minimum_required(VERSION 3.12)

project(ament_python_test_package)

find_package(ament_cmake_core REQUIRED)

find_package(ament_cmake_python REQUIRED)

ament_python_install_package(${PROJECT_NAME})

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 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.
#

class Bar:
def __init__() -> None:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ament_python_test_package</name>
<version>0.0.0</version>
<description>Minimal python package to test python cmake install</description>

<maintainer email="[email protected]">Nadav Elkabets</maintainer>

<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_core</buildtool_depend>
<build_depend>ament_cmake_python</build_depend>

<buildtool_export_depend>ament_cmake_core</buildtool_export_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2025 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.

cmake_minimum_required(VERSION 3.12)

project(ament_python_test_package_overlay)

find_package(ament_cmake_core REQUIRED)

find_package(ament_cmake_python REQUIRED)

ament_python_install_package(
ament_python_test_package_overlay
PACKAGE_DIR "${CMAKE_CURRENT_LIST_DIR}/ament_python_test_package"
)
ament_python_install_package(
ament_python_test_package_overlay
PACKAGE_DIR "${CMAKE_CURRENT_LIST_DIR}/ament_python_test_package_overlay"
)

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 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.
#

class Bar:
def __init__() -> None:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2025 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 subdir.utils import foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 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.
#

def foo() -> None:
pass
Loading