Skip to content

Commit

Permalink
Changes in cmake to run python tests with colcon
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Wagner <[email protected]>
  • Loading branch information
WagnerMarcos committed Jul 29, 2021
1 parent 5fa9264 commit bca2353
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/angle_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Modify the PYTHONPATH environment variable to include the ignition math
# library install path. For example, if you install to /user:
#
# $ export PYTHONPATH=/usr/lib/python/ignition:$PYTHONPATH
# $ export PYTHONPATH=/usr/lib/python/:$PYTHONPATH
#

import ignition.math
Expand Down
19 changes: 18 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ endif()
#################################
# Create and install Python interfaces
# Example usage
# $ export PYTHONPATH=/ws/install/lib/python/ignition
# $ export PYTHONPATH=/ws/install/lib/python/:$PYTHONPATH
if (PYTHONLIBS_FOUND)
set_source_files_properties(python/python.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(python/python.i PROPERTIES SWIG_FLAGS "-includeall")
Expand Down Expand Up @@ -122,4 +122,21 @@ if (PYTHONLIBS_FOUND)
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-shadow -Wno-maybe-uninitialized -Wno-unused-parameter -Wno-cast-function-type -Wno-missing-field-initializers>
)
install(TARGETS ${SWIG_PY_LIB} DESTINATION ${IGN_LIB_INSTALL_DIR}/python/ignition)

# Add the Python tests

set(python_files
python
Vector3
)

foreach (python_file ${python_files})
list(APPEND python_tests ${python_file}_TEST)
endforeach()

foreach (test ${python_tests})
add_test(NAME ${test}.py COMMAND
python3 ${CMAKE_SOURCE_DIR}/src/${test}.py)
endforeach()

endif()
15 changes: 15 additions & 0 deletions src/python_TEST.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import unittest
import ignition.math
class TestVector3(unittest.TestCase):

def test_construction(self):
angle1 = ignition.math.Angle()
self.assertEqual(angle1.Radian(), 0.0)
v1 = ignition.math.Vector3d(0, 0, 0)
self.assertEqual(v1, ignition.math.Vector3d.Zero)
v2 = ignition.math.Vector2d(1, 2)
self.assertEqual(v2.X(), 1)
self.assertEqual(v2.Y(), 2)

if __name__ == '__main__':
unittest.main()

0 comments on commit bca2353

Please sign in to comment.