From 9b1fecd98efca01fa9d8aba59285afcf046a2880 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 23 Aug 2022 09:55:12 -0400 Subject: [PATCH] fix: typing --- tests/test_robot.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/test_robot.py b/tests/test_robot.py index 901126ba..9f023ae0 100644 --- a/tests/test_robot.py +++ b/tests/test_robot.py @@ -3,6 +3,7 @@ import hypothesis import numpy as np +import numpy.typing as npt from hypothesis import given from hypothesis.extra.numpy import arrays from hypothesis.strategies import floats @@ -14,7 +15,7 @@ from pybotics.robot import Robot -def test_fk(resources_path: Path): +def test_fk(resources_path: Path) -> None: """ Test robot. @@ -23,7 +24,7 @@ def test_fk(resources_path: Path): """ # get resource path = resources_path / "ur10-joints-poses.csv" - data = np.loadtxt(str(path), delimiter=",") + data = np.loadtxt(str(path), delimiter=",") # type: ignore # load robot robot = Robot.from_parameters(ur10()) @@ -38,23 +39,23 @@ def test_fk(resources_path: Path): # test with position argument actual_pose = robot.fk(q=joints) - np.testing.assert_allclose(actual_pose, desired_pose, atol=atol) + np.testing.assert_allclose(actual_pose, desired_pose, atol=atol) # type: ignore # test with internal position attribute robot.joints = joints actual_pose = robot.fk() - np.testing.assert_allclose(actual_pose, desired_pose, atol=atol) + np.testing.assert_allclose(actual_pose, desired_pose, atol=atol) # type: ignore -def test_home_position(): +def test_home_position() -> None: """Test.""" robot = Robot.from_parameters(ur10()) x = np.ones(len(robot)) robot.home_position = x - np.testing.assert_allclose(robot.home_position, x) + np.testing.assert_allclose(robot.home_position, x) # type: ignore -def test_joint_limits(): +def test_joint_limits() -> None: """Test.""" robot = Robot.from_parameters(ur10()) @@ -69,7 +70,7 @@ def test_joint_limits(): robot.joints = robot.joint_limits.copy()[1] + 10 -def test_compute_joint_torques(planar_robot: Robot): +def test_compute_joint_torques(planar_robot: Robot) -> None: """ Test. @@ -79,9 +80,9 @@ def test_compute_joint_torques(planar_robot: Robot): :return: """ # set test force and angles - force = [-100, -200, 0] - moment = [0] * 3 - wrench = force + moment + force = np.array([-100, -200, 0]) + moment = np.zeros(3) + wrench = force + moment # type: npt.NDArray[np.float64] joint_angles = np.deg2rad([30, 60, 0]) # get link lengths @@ -102,11 +103,11 @@ def test_compute_joint_torques(planar_robot: Robot): # test actual_torques = planar_robot.compute_joint_torques(q=joint_angles, wrench=wrench) - np.testing.assert_allclose(actual_torques, expected_torques) + np.testing.assert_allclose(actual_torques, expected_torques) # type: ignore planar_robot.joints = joint_angles actual_torques = planar_robot.compute_joint_torques(wrench=wrench) - np.testing.assert_allclose(actual_torques, expected_torques) + np.testing.assert_allclose(actual_torques, expected_torques) # type: ignore @given( @@ -118,7 +119,7 @@ def test_compute_joint_torques(planar_robot: Robot): ), ) ) -def test_jacobian_world(q: npt.NDArray[np.float64], planar_robot: Robot): +def test_jacobian_world(q: npt.NDArray[np.float64], planar_robot: Robot) -> None: """Test.""" # get link lengths # FIXME: "Link" has no attribute "a" @@ -145,7 +146,7 @@ def test_jacobian_world(q: npt.NDArray[np.float64], planar_robot: Robot): expected[-1, :] = 1 actual = planar_robot.jacobian_world(q) - np.testing.assert_allclose(actual, expected, atol=1e-3) + np.testing.assert_allclose(actual, expected, atol=1e-3) # type: ignore @given( @@ -153,7 +154,7 @@ def test_jacobian_world(q: npt.NDArray[np.float64], planar_robot: Robot): shape=(3,), dtype=float, elements=floats(allow_nan=False, allow_infinity=False) ) ) -def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot): +def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot) -> None: """Test.""" # get link lengths # FIXME: "Link" has no attribute "a" @@ -176,7 +177,7 @@ def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot): expected[-1, :] = 1 actual = planar_robot.jacobian_flange(q) - np.testing.assert_allclose(actual, expected, atol=1e-6) + np.testing.assert_allclose(actual, expected, atol=1e-6) # type: ignore @given( @@ -199,7 +200,7 @@ def test_jacobian_flange(q: npt.NDArray[np.float64], planar_robot: Robot): ), ) @hypothesis.settings(deadline=None) -def test_ik(q: npt.NDArray[np.float64], q_offset: npt.NDArray[np.float64]): +def test_ik(q: npt.NDArray[np.float64], q_offset: npt.NDArray[np.float64]) -> None: """Test.""" robot = Robot.from_parameters(ur10()) pose = robot.fk(q) @@ -216,22 +217,22 @@ def test_ik(q: npt.NDArray[np.float64], q_offset: npt.NDArray[np.float64]): # test the matrix with lower accuracy # rotation components are hard to achieve when x0 isn't good - np.testing.assert_allclose(actual_pose, pose, atol=1) + np.testing.assert_allclose(actual_pose, pose, atol=1) # type: ignore # test the position with higher accuracy desired_position = pose[:-1, -1] actual_position = actual_pose[:-1, -1] - np.testing.assert_allclose(actual_position, desired_position, atol=1e-1) + np.testing.assert_allclose(actual_position, desired_position, atol=1e-1) # type: ignore -def test_random_joints(): +def test_random_joints() -> None: """Test.""" robot = Robot.from_parameters(ur10()) robot.random_joints() robot.random_joints(in_place=True) -def test_to_json(): +def test_to_json() -> None: """Test.""" robot = Robot.from_parameters(ur10()) robot.to_json()