-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
169 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# It's necessary to install the python modules for the test. | ||
make install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ libprotoc-dev | |
libtinyxml2-dev | ||
protobuf-compiler | ||
ruby | ||
python3-pytest | ||
python3-protobuf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Append `_configured` to the file name so it doesn't interfere with tests. | ||
# This happens because pytest will load the `gz.msgs` package from the build directory | ||
# (because there's an __init__.py file there) instead of being redirected to | ||
# `gz.msgs10` in the install directory, which is the intent of this `__init__.py` file. | ||
set(python_init_file ${PROJECT_BINARY_DIR}/python/gz/${GS_DESIGNATION}/__init__.py_configured) | ||
configure_file(${PROJECT_SOURCE_DIR}/python/src/__init__.py.in ${python_init_file}) | ||
|
||
install(FILES ${python_init_file} DESTINATION ${CMAKE_INSTALL_PREFIX}/${GZ_LIB_INSTALL_DIR}/python/gz/${GZ_DESIGNATION}${PROJECT_VERSION_MAJOR} RENAME __init__.py) | ||
|
||
if (BUILD_TESTING AND NOT WIN32) | ||
set(python_tests | ||
basic_TEST | ||
) | ||
execute_process(COMMAND "${Python3_EXECUTABLE}" -m pytest --version | ||
OUTPUT_VARIABLE PYTEST_output | ||
ERROR_VARIABLE PYTEST_error | ||
RESULT_VARIABLE PYTEST_result) | ||
if(${PYTEST_result} EQUAL 0) | ||
set(pytest_FOUND TRUE) | ||
else() | ||
message(WARNING "Pytest package not available: ${PYTEST_error}") | ||
message(WARNING "Output: ${PYTEST_output}") | ||
endif() | ||
|
||
foreach (test ${python_tests}) | ||
if (pytest_FOUND) | ||
add_test(NAME ${test}.py COMMAND | ||
"${Python3_EXECUTABLE}" -m pytest "${CMAKE_SOURCE_DIR}/python/test/${test}.py" --junitxml "${CMAKE_BINARY_DIR}/test_results/${test}.xml") | ||
else() | ||
add_test(NAME ${test}.py COMMAND | ||
"${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/test/${test}.py") | ||
endif() | ||
set(_env_vars "PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/") | ||
set_tests_properties(${test}.py PROPERTIES ENVIRONMENT "${_env_vars}") | ||
endforeach() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (C) 2023 Open Source Robotics Foundation | ||
# | ||
# 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 is a workaround for a limitation in out protobuf python generation | ||
# where a message that depends on another message will try to import the | ||
# corresponding python module using `gz.msgs` as the package name. However, | ||
# we're installing the python modules in a directory that contains the gz-msgs | ||
# major version number, so the import fails. This hack here overwrites the | ||
# entry for the unversioned module name in `sys.modules` to point to the | ||
# versioned module the first time a message module is loaded. Subsequent | ||
# imports with or without the major version number will work properly. | ||
|
||
import sys | ||
|
||
unversioned_module = "gz.msgs" | ||
versioned_module = "gz.msgs@PROJECT_VERSION_MAJOR@" | ||
if unversioned_module in sys.modules: | ||
print("Looks like you are combining different versions of {}. Found {} and" | ||
"{} This is not supported".format(sys.modules[unversioned_module], | ||
sys.modules[versioned_module])) | ||
else: | ||
sys.modules[unversioned_module] = sys.modules[versioned_module] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright (C) 2023 Open Source Robotics Foundation | ||
# | ||
# 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 gz.msgs10.vector3d_pb2 import Vector3d | ||
|
||
import unittest | ||
|
||
|
||
class BasicTest(unittest.TestCase): | ||
|
||
def test_serialization(self): | ||
msg = Vector3d() | ||
msg.x = 1 | ||
msg.y = 2 | ||
msg.z = 3 | ||
|
||
serialized_msg = msg.SerializeToString() | ||
self.assertGreater(len(serialized_msg), 0) | ||
|
||
msg_from_serialized = Vector3d() | ||
self.assertNotEqual(msg_from_serialized, msg) | ||
msg_from_serialized.ParseFromString(serialized_msg) | ||
self.assertEqual(msg_from_serialized, msg) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters