-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for rail side validation
- Loading branch information
Showing
3 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
raillabel_providerkit/validation/validate_rail_side/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.""" |
22 changes: 22 additions & 0 deletions
22
raillabel_providerkit/validation/validate_rail_side/validate_rail_side.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
205 changes: 205 additions & 0 deletions
205
tests/test_raillabel_providerkit/validation/validate_rail_side/test_validate_rail_side.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |