def test_round_trip() -> None: """Test round trip of serialization, then de-serialization.""" bSc = Sim2(R=np.array([[0, 1], [1, 0]]), t=np.array([-5, 5]), s=0.1) save_fpath = TEST_DATA_ROOT / "b_Sim2_c.json" bSc.save_as_json(save_fpath=save_fpath) bSc_ = Sim2.from_json(save_fpath) assert bSc_ == bSc
def test_from_json() -> None: """Ensure that classmethod can construct an object instance from a json file.""" json_fpath = TEST_DATA_ROOT / "a_Sim2_b.json" aSb = Sim2.from_json(json_fpath) expected_rotation = np.array([[1.0, 0.0], [0.0, 1.0]]) expected_translation = np.array([3930.0, 3240.0]) expected_scale = 1.6666666666666667 assert np.allclose(aSb.rotation, expected_rotation) assert np.allclose(aSb.translation, expected_translation) assert np.isclose(aSb.scale, expected_scale)
def test_from_json_invalid_scale() -> None: """Ensure that classmethod raises an error with invalid JSON input.""" json_fpath = TEST_DATA_ROOT / "a_Sim2_b___invalid.json" with pytest.raises(ZeroDivisionError) as e_info: aSb = Sim2.from_json(json_fpath)