def test_deactivate_transform_precision_error(): A2B = np.eye(4) A2B[0, 0] = 2.0 A2B[3, 0] = 3.0 assert_raises_regexp(ValueError, "Expected rotation matrix", check_transform, A2B) if int(platform.python_version()[0]) == 2: # Python 2 seems to incorrectly suppress some warnings, not sure why n_expected_warnings = 2 else: n_expected_warnings = 3 try: warnings.filterwarnings("always", category=UserWarning) with warnings.catch_warnings(record=True) as w: check_transform(A2B, strict_check=False) assert_equal(len(w), n_expected_warnings) finally: warnings.filterwarnings("default", category=UserWarning)
def test_check_transform(): """Test input validation for transformation matrix.""" A2B = np.eye(3) assert_raises_regexp( ValueError, "Expected homogeneous transformation matrix with shape", check_transform, A2B) A2B = np.eye(4, dtype=int) A2B = check_transform(A2B) assert_equal(type(A2B), np.ndarray) assert_equal(A2B.dtype, np.float64) A2B[:3, :3] = np.array([[1, 1, 1], [0, 0, 0], [2, 2, 2]]) assert_raises_regexp(ValueError, "rotation matrix", check_transform, A2B) A2B = np.eye(4) A2B[3, :] = np.array([0.1, 0.0, 0.0, 1.0]) assert_raises_regexp(ValueError, "homogeneous transformation matrix", check_transform, A2B) random_state = np.random.RandomState(0) A2B = random_transform(random_state) A2B2 = check_transform(A2B) assert_array_almost_equal(A2B, A2B2)