diff --git a/tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py b/tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py index e46cff5..dc5b26f 100644 --- a/tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py +++ b/tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py @@ -6,19 +6,143 @@ from raillabel_providerkit.validation.validate_rail_side.validate_rail_side import ( validate_rail_side, + _count_rails_per_track_in_frame, ) -def test_validate_rail_side__no_errors(empty_scene, empty_frame): - scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) - scene.objects[object.uid] = object - sensor = raillabel.format.Sensor( +@pytest.fixture +def example_camera_1() -> raillabel.format.Sensor: + return raillabel.format.Sensor( uid="rgb_center", type=raillabel.format.SensorType.CAMERA, ) + + +@pytest.fixture +def example_camera_2() -> raillabel.format.Sensor: + return raillabel.format.Sensor( + uid="ir_center", + type=raillabel.format.SensorType.CAMERA, + ) + + +@pytest.fixture +def example_track_1() -> raillabel.format.Object: + return raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" + ) + + +@pytest.fixture +def example_track_2() -> raillabel.format.Object: + return raillabel.format.Object( + uid="6e92e7af-3bc8-4225-b538-16d19e3f8aa7", name="track0002", type="track" + ) + + +def test_count_rails_per_track_in_frame__empty(empty_frame): + frame = empty_frame + results = _count_rails_per_track_in_frame(frame) + assert len(results) == 0 + + +def test_count_rails_per_track_in_frame__many_rails_for_one_track( + empty_frame, example_camera_1, example_track_1 +): + frame = empty_frame + sensor = example_camera_1 + object = example_track_1 + + LEFT_COUNT = 32 + RIGHT_COUNT = 42 + + for i in range(LEFT_COUNT): + uid = f"test_left_{i}" + frame.annotations[uid] = raillabel.format.Poly2d( + uid=uid, + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={"railSide": "leftRail"}, + ) + + for i in range(RIGHT_COUNT): + uid = f"test_right_{i}" + frame.annotations[uid] = raillabel.format.Poly2d( + uid=uid, + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={"railSide": "rightRail"}, + ) + + results = _count_rails_per_track_in_frame(frame) + assert len(results) == 1 + assert object.uid in results.keys() + assert results[object.uid] == (LEFT_COUNT, RIGHT_COUNT) + + +def test_count_rails_per_track_in_frame__many_rails_for_two_tracks( + empty_frame, example_camera_1, example_track_1, example_track_2 +): + frame = empty_frame + sensor = example_camera_1 + object1 = example_track_1 + object2 = example_track_2 + + LEFT_COUNT = 32 + RIGHT_COUNT = 42 + + for object in [object1, object2]: + for i in range(LEFT_COUNT): + uid = f"test_left_{i}_object_{object.uid}" + frame.annotations[uid] = raillabel.format.Poly2d( + uid=uid, + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={"railSide": "leftRail"}, + ) + + for i in range(RIGHT_COUNT): + uid = f"test_right_{i}_object_{object.uid}" + frame.annotations[uid] = raillabel.format.Poly2d( + uid=uid, + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={"railSide": "rightRail"}, + ) + + results = _count_rails_per_track_in_frame(frame) + assert len(results) == 2 + assert object1.uid in results.keys() + assert object2.uid in results.keys() + assert results[object1.uid] == (LEFT_COUNT, RIGHT_COUNT) + assert results[object2.uid] == (LEFT_COUNT, RIGHT_COUNT) + + +def test_validate_rail_side__no_errors(empty_scene, empty_frame, example_camera_1, example_track_1): + scene = empty_scene + object = example_track_1 + scene.objects[object.uid] = object + sensor = example_camera_1 scene.sensors[sensor.uid] = sensor frame = empty_frame frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( @@ -49,16 +173,13 @@ def test_validate_rail_side__no_errors(empty_scene, empty_frame): assert len(actual) == 0 -def test_validate_rail_side__rail_sides_switched(empty_scene, empty_frame): +def test_validate_rail_side__rail_sides_switched( + empty_scene, empty_frame, example_camera_1, example_track_1 +): scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) + object = example_track_1 scene.objects[object.uid] = object - sensor = raillabel.format.Sensor( - uid="rgb_center", - type=raillabel.format.SensorType.CAMERA, - ) + sensor = example_camera_1 scene.sensors[sensor.uid] = sensor frame = empty_frame frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( @@ -89,16 +210,13 @@ def test_validate_rail_side__rail_sides_switched(empty_scene, empty_frame): assert len(actual) == 1 -def test_validate_rail_side__two_left_rails(empty_scene, empty_frame): +def test_validate_rail_side__two_left_rails( + empty_scene, empty_frame, example_camera_1, example_track_1 +): scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) + object = example_track_1 scene.objects[object.uid] = object - sensor = raillabel.format.Sensor( - uid="rgb_center", - type=raillabel.format.SensorType.CAMERA, - ) + sensor = example_camera_1 scene.sensors[sensor.uid] = sensor frame = empty_frame frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( @@ -129,16 +247,13 @@ def test_validate_rail_side__two_left_rails(empty_scene, empty_frame): assert len(actual) == 1 -def test_validate_rail_side__two_right_rails(empty_scene, empty_frame): +def test_validate_rail_side__two_right_rails( + empty_scene, empty_frame, example_camera_1, example_track_1 +): scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) + object = example_track_1 scene.objects[object.uid] = object - sensor = raillabel.format.Sensor( - uid="rgb_center", - type=raillabel.format.SensorType.CAMERA, - ) + sensor = example_camera_1 scene.sensors[sensor.uid] = sensor frame = empty_frame frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( @@ -169,20 +284,14 @@ def test_validate_rail_side__two_right_rails(empty_scene, empty_frame): assert len(actual) == 1 -def test_validate_rail_side__two_sensors_with_two_right_rails_each(empty_scene, empty_frame): +def test_validate_rail_side__two_sensors_with_two_right_rails_each( + empty_scene, empty_frame, example_camera_1, example_camera_2, example_track_1 +): scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) + object = example_track_1 scene.objects[object.uid] = object - sensor1 = raillabel.format.Sensor( - uid="rgb_center", - type=raillabel.format.SensorType.CAMERA, - ) - sensor2 = raillabel.format.Sensor( - uid="ir_center", - type=raillabel.format.SensorType.CAMERA, - ) + sensor1 = example_camera_1 + sensor2 = example_camera_2 for sensor in [sensor1, sensor2]: scene.sensors[sensor.uid] = sensor frame = empty_frame @@ -236,20 +345,14 @@ def test_validate_rail_side__two_sensors_with_two_right_rails_each(empty_scene, assert len(actual) == 2 -def test_validate_rail_side__two_sensors_with_one_right_rail_each(empty_scene, empty_frame): +def test_validate_rail_side__two_sensors_with_one_right_rail_each( + empty_scene, empty_frame, example_camera_1, example_camera_2, example_track_1 +): scene = empty_scene - object = raillabel.format.Object( - uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", name="track0001", type="track" - ) + object = example_track_1 scene.objects[object.uid] = object - sensor1 = raillabel.format.Sensor( - uid="rgb_center", - type=raillabel.format.SensorType.CAMERA, - ) - sensor2 = raillabel.format.Sensor( - uid="ir_center", - type=raillabel.format.SensorType.CAMERA, - ) + sensor1 = example_camera_1 + sensor2 = example_camera_2 for sensor in [sensor1, sensor2]: scene.sensors[sensor.uid] = sensor frame = empty_frame