From f48e77f983be5c1d2311992929059c9c347f8299 Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 28 Oct 2024 15:25:36 +0100 Subject: [PATCH] test: add tests for rail side validation --- .../validation/validate_rail_side/__init__.py | 3 + .../validate_rail_side/validate_rail_side.py | 22 ++ .../test_validate_rail_side.py | 205 ++++++++++++++++++ 3 files changed, 230 insertions(+) create mode 100644 raillabel_providerkit/validation/validate_rail_side/__init__.py create mode 100644 raillabel_providerkit/validation/validate_rail_side/validate_rail_side.py create mode 100644 tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py diff --git a/raillabel_providerkit/validation/validate_rail_side/__init__.py b/raillabel_providerkit/validation/validate_rail_side/__init__.py new file mode 100644 index 0000000..3f71fbc --- /dev/null +++ b/raillabel_providerkit/validation/validate_rail_side/__init__.py @@ -0,0 +1,3 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 +"""Package for validating a scene for empty frames.""" diff --git a/raillabel_providerkit/validation/validate_rail_side/validate_rail_side.py b/raillabel_providerkit/validation/validate_rail_side/validate_rail_side.py new file mode 100644 index 0000000..a2111ed --- /dev/null +++ b/raillabel_providerkit/validation/validate_rail_side/validate_rail_side.py @@ -0,0 +1,22 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +from typing import List + +import raillabel + + +def validate_rail_side(scene: raillabel.Scene) -> List[str]: + """TODO. + + Parameters + ---------- + scene : raillabel.Scene + Scene, that should be validated. + + Returns + ------- + list[str] + list of all rail side errors in the scene. If an empty list is returned, then there are no + errors present. + """ 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 new file mode 100644 index 0000000..9792561 --- /dev/null +++ b/tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py @@ -0,0 +1,205 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +import pytest +import raillabel + +from raillabel_providerkit.validation.validate_rail_side.validate_rail_side import ( + validate_rail_side, +) + + +def test_validate_rail_side__no_errors(empty_scene, empty_frame): + scene = empty_scene + scene.objects["a1082ef9-555b-4b69-a888-7da531d8a2eb"] = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + object = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + sensor = raillabel.format.Sensor( + uid="rgb_center", + type=raillabel.format.SensorType.CAMERA, + ) + frame = empty_frame + frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( + uid="325b1f55-a2ef-475f-a780-13e1a9e823c3", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={ + "railSide": "leftRail" + } + ) + frame.annotations["be7d136a-8364-4fbd-b098-6f4a21205d22"] = raillabel.format.Poly2d( + uid="be7d136a-8364-4fbd-b098-6f4a21205d22", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={ + "railSide": "rightRail" + } + ) + + actual = validate_rail_side(scene) + assert len(actual) == 0 + + +def test_validate_rail_side__rail_sides_switched(empty_scene, empty_frame): + scene = empty_scene + scene.objects["a1082ef9-555b-4b69-a888-7da531d8a2eb"] = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + object = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + sensor = raillabel.format.Sensor( + uid="rgb_center", + type=raillabel.format.SensorType.CAMERA, + ) + frame = empty_frame + frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( + uid="325b1f55-a2ef-475f-a780-13e1a9e823c3", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={ + "railSide": "rightRail" + } + ) + frame.annotations["be7d136a-8364-4fbd-b098-6f4a21205d22"] = raillabel.format.Poly2d( + uid="be7d136a-8364-4fbd-b098-6f4a21205d22", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={ + "railSide": "leftRail" + } + ) + + actual = validate_rail_side(scene) + assert len(actual) == 1 + + +def test_validate_rail_side__two_left_rails(empty_scene, empty_frame): + scene = empty_scene + scene.objects["a1082ef9-555b-4b69-a888-7da531d8a2eb"] = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + object = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + sensor = raillabel.format.Sensor( + uid="rgb_center", + type=raillabel.format.SensorType.CAMERA, + ) + frame = empty_frame + frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( + uid="325b1f55-a2ef-475f-a780-13e1a9e823c3", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={ + "railSide": "leftRail" + } + ) + frame.annotations["be7d136a-8364-4fbd-b098-6f4a21205d22"] = raillabel.format.Poly2d( + uid="be7d136a-8364-4fbd-b098-6f4a21205d22", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={ + "railSide": "leftRail" + } + ) + + actual = validate_rail_side(scene) + assert len(actual) == 1 + + +def test_validate_rail_side__two_right_rails(empty_scene, empty_frame): + scene = empty_scene + scene.objects["a1082ef9-555b-4b69-a888-7da531d8a2eb"] = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + object = raillabel.format.Object( + uid="a1082ef9-555b-4b69-a888-7da531d8a2eb", + name="track0001", + type="track" + ) + sensor = raillabel.format.Sensor( + uid="rgb_center", + type=raillabel.format.SensorType.CAMERA, + ) + frame = empty_frame + frame.annotations["325b1f55-a2ef-475f-a780-13e1a9e823c3"] = raillabel.format.Poly2d( + uid="325b1f55-a2ef-475f-a780-13e1a9e823c3", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(0, 0), + raillabel.format.Point2d(0, 1), + ], + closed=False, + attributes={ + "railSide": "rightRail" + } + ) + frame.annotations["be7d136a-8364-4fbd-b098-6f4a21205d22"] = raillabel.format.Poly2d( + uid="be7d136a-8364-4fbd-b098-6f4a21205d22", + object=object, + sensor=sensor, + points=[ + raillabel.format.Point2d(1, 0), + raillabel.format.Point2d(1, 1), + ], + closed=False, + attributes={ + "railSide": "rightRail" + } + ) + + actual = validate_rail_side(scene) + assert len(actual) == 1 + + +if __name__ == "__main__": + pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])