Skip to content

Commit

Permalink
feat: implement OtherSensor.to_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 14, 2024
1 parent 0060945 commit 43d91f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions raillabel/format/other_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@ def from_json(
uri=json_stream.uri,
description=json_stream.description,
)

def to_json(self) -> tuple[JSONStreamOther, JSONCoordinateSystem]:
"""Export this object into the RailLabel JSON format."""
return (
JSONStreamOther(
type="other",
uri=self.uri,
description=self.description,
),
JSONCoordinateSystem(
parent="base",
type="sensor",
pose_wrt_parent=self.extrinsics.to_json() if self.extrinsics is not None else None,
),
)
7 changes: 6 additions & 1 deletion tests/test_raillabel/format/test_other_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def other_json(transform_json) -> tuple[JSONStreamOther, JSONCoordinateSystem]:
description="A very nice generic sensor",
),
JSONCoordinateSystem(
parent="base", type="sensor", pose_wrt_parent=transform_json, children=[]
parent="base", type="sensor", pose_wrt_parent=transform_json, children=None
),
)

Expand All @@ -42,5 +42,10 @@ def test_from_json(other, other_json):
assert actual == other


def test_to_json(other, other_json):
actual = other.to_json()
assert actual == other_json


if __name__ == "__main__":
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])

0 comments on commit 43d91f9

Please sign in to comment.