Skip to content

Commit

Permalink
test: add tests for rail side validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 28, 2024
1 parent e7f5b13 commit f48e77f
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Package for validating a scene for empty frames."""
Original file line number Diff line number Diff line change
@@ -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.
"""
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit f48e77f

Please sign in to comment.