From 68b463c5566f4f1c1d15e7d5458b084e930953b4 Mon Sep 17 00:00:00 2001 From: unexcellent <> Date: Wed, 13 Nov 2024 09:16:17 +0100 Subject: [PATCH] test: extract object uids into separate fixtures --- tests/test_raillabel/format/conftest.py | 8 +++++ tests/test_raillabel/format/test_bbox.py | 7 ++-- tests/test_raillabel/format/test_cuboid.py | 7 ++-- tests/test_raillabel/format/test_object.py | 39 ++++++++++++++++++++-- tests/test_raillabel/format/test_poly2d.py | 7 ++-- tests/test_raillabel/format/test_poly3d.py | 7 ++-- tests/test_raillabel/format/test_seg3d.py | 7 ++-- 7 files changed, 64 insertions(+), 18 deletions(-) diff --git a/tests/test_raillabel/format/conftest.py b/tests/test_raillabel/format/conftest.py index 265e9a4..328cc33 100644 --- a/tests/test_raillabel/format/conftest.py +++ b/tests/test_raillabel/format/conftest.py @@ -10,6 +10,14 @@ from .test_lidar import lidar, lidar_json from .test_metadata import metadata, metadata_json from .test_num import num, num_json +from .test_object import ( + object_person, + object_person_json, + object_person_uid, + object_track, + object_track_json, + object_track_uid, +) from .test_point2d import point2d, point2d_json, another_point2d, another_point2d_json from .test_point3d import point3d, point3d_json, another_point3d, another_point3d_json from .test_poly2d import poly2d, poly2d_json, poly2d_uid diff --git a/tests/test_raillabel/format/test_bbox.py b/tests/test_raillabel/format/test_bbox.py index b615508..d6c670f 100644 --- a/tests/test_raillabel/format/test_bbox.py +++ b/tests/test_raillabel/format/test_bbox.py @@ -38,21 +38,22 @@ def bbox( point2d, size2d, attributes_multiple_types, + object_person_uid, ) -> Bbox: return Bbox( pos=point2d, size=size2d, sensor="rgb_middle", attributes=attributes_multiple_types, - object=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934"), + object=object_person_uid, ) # == Tests ============================ -def test_from_json(bbox, bbox_json): - actual = Bbox.from_json(bbox_json, object_uid=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934")) +def test_from_json(bbox, bbox_json, object_person_uid): + actual = Bbox.from_json(bbox_json, object_person_uid) assert actual == bbox diff --git a/tests/test_raillabel/format/test_cuboid.py b/tests/test_raillabel/format/test_cuboid.py index b8937b3..855777c 100644 --- a/tests/test_raillabel/format/test_cuboid.py +++ b/tests/test_raillabel/format/test_cuboid.py @@ -40,6 +40,7 @@ def cuboid( size3d, quaternion, attributes_multiple_types, + object_person_uid, ) -> Cuboid: return Cuboid( pos=point3d, @@ -47,15 +48,15 @@ def cuboid( size=size3d, sensor="lidar", attributes=attributes_multiple_types, - object=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934"), + object=object_person_uid, ) # == Tests ============================ -def test_from_json(cuboid, cuboid_json): - actual = Cuboid.from_json(cuboid_json, object_uid=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934")) +def test_from_json(cuboid, cuboid_json, object_person_uid): + actual = Cuboid.from_json(cuboid_json, object_person_uid) assert actual == cuboid diff --git a/tests/test_raillabel/format/test_object.py b/tests/test_raillabel/format/test_object.py index 65d37a5..0f94c7a 100644 --- a/tests/test_raillabel/format/test_object.py +++ b/tests/test_raillabel/format/test_object.py @@ -3,6 +3,8 @@ from __future__ import annotations +from uuid import UUID + import pytest from raillabel.json_format import JSONObject @@ -14,7 +16,7 @@ @pytest.fixture def object_person_json() -> JSONObject: return JSONObject( - name="person0032", + name="person_0032", type="person", ) @@ -22,18 +24,49 @@ def object_person_json() -> JSONObject: @pytest.fixture def object_person() -> Object: return Object( - name="person0032", + name="person_0032", type="person", ) +@pytest.fixture +def object_person_uid() -> UUID: + return UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934") + + +@pytest.fixture +def object_track_json() -> JSONObject: + return JSONObject( + name="track_0001", + type="track", + ) + + +@pytest.fixture +def object_track() -> Object: + return Object( + name="track_0001", + type="track", + ) + + +@pytest.fixture +def object_track_uid() -> UUID: + return UUID("cfcf9750-3BC3-4077-9079-a82c0c63976a") + + # == Tests ============================ -def test_from_json(object_person, object_person_json): +def test_from_json__person(object_person, object_person_json): actual = Object.from_json(object_person_json) assert actual == object_person +def test_from_json__track(object_track, object_track_json): + actual = Object.from_json(object_track_json) + assert actual == object_track + + if __name__ == "__main__": pytest.main([__file__, "-v"]) diff --git a/tests/test_raillabel/format/test_poly2d.py b/tests/test_raillabel/format/test_poly2d.py index f707bd9..d021f15 100644 --- a/tests/test_raillabel/format/test_poly2d.py +++ b/tests/test_raillabel/format/test_poly2d.py @@ -40,21 +40,22 @@ def poly2d( point2d, another_point2d, attributes_multiple_types, + object_track_uid, ) -> Poly2d: return Poly2d( points=[point2d, another_point2d], closed=True, sensor="rgb_middle", attributes=attributes_multiple_types, - object=UUID("cfcf9750-3BC3-4077-9079-a82c0c63976a"), + object=object_track_uid, ) # == Tests ============================ -def test_from_json(poly2d, poly2d_json): - actual = Poly2d.from_json(poly2d_json, object_uid=UUID("cfcf9750-3BC3-4077-9079-a82c0c63976a")) +def test_from_json(poly2d, poly2d_json, object_track_uid): + actual = Poly2d.from_json(poly2d_json, object_track_uid) assert actual == poly2d diff --git a/tests/test_raillabel/format/test_poly3d.py b/tests/test_raillabel/format/test_poly3d.py index 9fa0a6c..1467037 100644 --- a/tests/test_raillabel/format/test_poly3d.py +++ b/tests/test_raillabel/format/test_poly3d.py @@ -39,21 +39,22 @@ def poly3d( point3d, another_point3d, attributes_multiple_types, + object_track_uid, ) -> Poly3d: return Poly3d( points=[point3d, another_point3d], closed=True, sensor="lidar", attributes=attributes_multiple_types, - object=UUID("cfcf9750-3bc3-4077-9079-a82c0c63976a"), + object=object_track_uid, ) # == Tests ============================ -def test_from_json(poly3d, poly3d_json): - actual = Poly3d.from_json(poly3d_json, object_uid=UUID("cfcf9750-3BC3-4077-9079-a82c0c63976a")) +def test_from_json(poly3d, poly3d_json, object_track_uid): + actual = Poly3d.from_json(poly3d_json, object_track_uid) assert actual == poly3d diff --git a/tests/test_raillabel/format/test_seg3d.py b/tests/test_raillabel/format/test_seg3d.py index f025e10..cd91e03 100644 --- a/tests/test_raillabel/format/test_seg3d.py +++ b/tests/test_raillabel/format/test_seg3d.py @@ -34,20 +34,21 @@ def seg3d_uid() -> UUID: @pytest.fixture def seg3d( attributes_multiple_types, + object_person_uid, ) -> Seg3d: return Seg3d( point_ids=[1234, 5678], sensor="lidar", attributes=attributes_multiple_types, - object=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934"), + object=object_person_uid, ) # == Tests ============================ -def test_from_json(seg3d, seg3d_json): - actual = Seg3d.from_json(seg3d_json, object_uid=UUID("b40ba3ad-0327-46ff-9c28-2506cfd6d934")) +def test_from_json(seg3d, seg3d_json, object_person_uid): + actual = Seg3d.from_json(seg3d_json, object_person_uid) assert actual == seg3d