Skip to content

Commit

Permalink
test: extract object uids into separate fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 13, 2024
1 parent 0fa89ec commit 68b463c
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 18 deletions.
8 changes: 8 additions & 0 deletions tests/test_raillabel/format/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/test_raillabel/format/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 4 additions & 3 deletions tests/test_raillabel/format/test_cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,23 @@ def cuboid(
size3d,
quaternion,
attributes_multiple_types,
object_person_uid,
) -> Cuboid:
return Cuboid(
pos=point3d,
quat=quaternion,
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


Expand Down
39 changes: 36 additions & 3 deletions tests/test_raillabel/format/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from __future__ import annotations

from uuid import UUID

import pytest

from raillabel.json_format import JSONObject
Expand All @@ -14,26 +16,57 @@
@pytest.fixture
def object_person_json() -> JSONObject:
return JSONObject(
name="person0032",
name="person_0032",
type="person",
)


@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"])
7 changes: 4 additions & 3 deletions tests/test_raillabel/format/test_poly2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 4 additions & 3 deletions tests/test_raillabel/format/test_poly3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 4 additions & 3 deletions tests/test_raillabel/format/test_seg3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 68b463c

Please sign in to comment.