diff --git a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml index 3d70fcebe..0796f4da1 100644 --- a/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml +++ b/subprojects/robotpy-wpimath/semiwrap/controls/TrapezoidProfile.yml @@ -48,6 +48,13 @@ classes: { std::string clsNameCopy = clsName; + cls_Constraints + .def("__repr__", [clsNameCopy](const Constraints &self) { + return clsNameCopy + ".Constraints(" + "maxVelocity=" + std::to_string(self.maxVelocity()) + ", " + "maxAcceleration=" + std::to_string(self.maxAcceleration()) + ")"; + }); + cls_State .def( py::init(), @@ -71,23 +78,10 @@ classes: ignore: true Velocity_t, Acceleration_t: param_override: - maxVelocity_: - name: maxVelocity + maxVelocity: default: '0' - maxAcceleration_: - name: maxAcceleration + maxAcceleration: default: '0' - template_inline_code: | - { - std::string clsNameCopy = clsName; - - cls_Constraints - .def("__repr__", [clsNameCopy](const Constraints &self) { - return clsNameCopy + ".Constraints(" - "maxVelocity=" + std::to_string(self.maxVelocity()) + ", " - "maxAcceleration=" + std::to_string(self.maxAcceleration()) + ")"; - }); - } frc::TrapezoidProfile::State: force_no_default_constructor: true attributes: diff --git a/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py new file mode 100644 index 000000000..e28c55c95 --- /dev/null +++ b/subprojects/robotpy-wpimath/tests/test_trapezoid_profile.py @@ -0,0 +1,24 @@ +import pytest + +from wpimath import trajectory + +trapezoid_profile_types = [ + trajectory.TrapezoidProfile, + trajectory.TrapezoidProfileRadians, +] + + +@pytest.mark.parametrize("TrapezoidProfile", trapezoid_profile_types) +def test_constraints_repr(TrapezoidProfile): + expected_qualname = f"{TrapezoidProfile.__name__}.Constraints" + constraints = TrapezoidProfile.Constraints() + + assert repr(constraints).startswith(f"{expected_qualname}(maxVelocity=0.") + + +@pytest.mark.parametrize("TrapezoidProfile", trapezoid_profile_types) +def test_state_repr(TrapezoidProfile): + expected_qualname = f"{TrapezoidProfile.__name__}.State" + constraints = TrapezoidProfile.State() + + assert repr(constraints).startswith(f"{expected_qualname}(position=0.")