From a4e789a4feef5c980229af26e8482029a313109e Mon Sep 17 00:00:00 2001 From: ManifoldFR Date: Thu, 19 Sep 2024 18:28:42 +0200 Subject: [PATCH] [tests/python] Properly gate some tests using pytest.mark.skipif [cmake] Remove some tests from list of Python tests depending on detected features --- tests/python/CMakeLists.txt | 10 +++++----- tests/python/test_continuous_dynamics.py | 12 +++++++++++- tests/python/test_finite_diff.py | 5 +++-- tests/python/test_frames.py | 4 ++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 7f54ff1d3..c0364d3a4 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -10,13 +10,13 @@ file( if(NOT BUILD_CROCODDYL_COMPAT) list(REMOVE_ITEM PYTHON_TESTS test_compat_croc.py) endif() -if(NOT BUILD_WITH_PINOCCHIO_PYTHON_BINDINGS) - list(REMOVE_ITEM PYTHON_TESTS test_constrained_dynamics.py) +if(NOT BUILD_WITH_PINOCCHIO_SUPPORT) + list(REMOVE_ITEM PYTHON_TESTS test_center_of_mass.py) list(REMOVE_ITEM PYTHON_TESTS test_frames.py) -endif() -if(NOT PINOCCHIO_V3) + list(REMOVE_ITEM PYTHON_TESTS test_rollout.py) +elseif(NOT PINOCCHIO_V3) + # Pinocchio support, but not Pinocchio 3 list(REMOVE_ITEM PYTHON_TESTS test_constrained_dynamics.py) - list(REMOVE_ITEM PYTHON_TESTS test_frames.py) endif() make_directory(${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/python/test_continuous_dynamics.py b/tests/python/test_continuous_dynamics.py index f9fa837c9..dda3f5e93 100644 --- a/tests/python/test_continuous_dynamics.py +++ b/tests/python/test_continuous_dynamics.py @@ -6,12 +6,13 @@ import numpy as np import aligator from aligator import dynamics, manifolds -from pinocchio import Quaternion +from eigenpy import Quaternion from utils import finite_diff, infNorm, create_multibody_ode epsilon = 1e-6 aligator.seed(42) np.random.seed(42) +HAS_PINOCCHIO = aligator.has_pinocchio_features() class MyODE(dynamics.ODEAbstract): @@ -71,6 +72,9 @@ def test_custom_ode(): assert len(xs) == 11 +@pytest.mark.skipif( + not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio." +) def test_multibody_free(): ode = create_multibody_ode(True) if ode is None: @@ -304,6 +308,9 @@ def test_continuous_centroidal_diff(): assert np.allclose(Judiff, Ju0, epsilon), "err={}".format(infNorm(Judiff - Ju0)) +@pytest.mark.skipif( + not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio." +) def test_kinodynamics(): import pinocchio as pin @@ -337,6 +344,9 @@ def test_kinodynamics(): ode.dForward(x0, u0, data) +@pytest.mark.skipif( + not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio." +) def test_kinodynamics_diff(): import pinocchio as pin diff --git a/tests/python/test_finite_diff.py b/tests/python/test_finite_diff.py index c247faee4..731fe7e82 100644 --- a/tests/python/test_finite_diff.py +++ b/tests/python/test_finite_diff.py @@ -42,7 +42,9 @@ def test_compute_jac_vs(): assert np.allclose(fdata1.Jy, fdata1b.Jy, 1e-2) -@pytest.mark.skipif(not HAS_PINOCCHIO, reason="Pinocchio bindings not present.") +@pytest.mark.skipif( + not HAS_PINOCCHIO, reason="Aligator was compiled without Pinocchio." +) def test_compute_jac_multibody(): model = pin.buildSampleModelHumanoid() space = manifolds.MultibodyConfiguration(model) @@ -87,7 +89,6 @@ def test_compute_cost_se3(): if __name__ == "__main__": - import pytest import sys sys.exit(pytest.main(sys.argv)) diff --git a/tests/python/test_frames.py b/tests/python/test_frames.py index 472a1e4de..31f3259d3 100644 --- a/tests/python/test_frames.py +++ b/tests/python/test_frames.py @@ -1,5 +1,6 @@ """ -Test function related to frames. +Test function related to Pinocchio frames. +This test is not added to CTest when CMake does not detect Pinocchio. """ import aligator @@ -194,4 +195,3 @@ def test_fly_high(): import pytest sys.exit(pytest.main(sys.argv)) - # test_frame_placement()