Skip to content

Commit

Permalink
feat: include validate_empty_frames() in validat()
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Dec 9, 2024
1 parent fa0e618 commit 4d415af
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ ignore = [
"D107", # __init__ docstrings are not necessary
"D203", # incompatible with D211
"D213", # incompatible with D212
"D413", # not relevant when using google or numpy docstring style

"FBT001", # flags in functions are not bad practice
"FBT002", # flags in functions are not bad practice
Expand Down
1 change: 1 addition & 0 deletions raillabel_providerkit/validation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Package for validating raillabel data regarding the format requirements."""

from .issue import Issue, IssueIdentifiers, IssueType
from .validate_empty_frames.validate_empty_frames import validate_empty_frames
from .validate_onthology.validate_onthology import validate_onthology
from .validate_schema import validate_schema

Expand Down
30 changes: 18 additions & 12 deletions raillabel_providerkit/validation/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@

from __future__ import annotations

from raillabel import Scene
from raillabel.json_format import JSONScene

from raillabel_providerkit.validation import Issue

from . import validate_schema
from . import validate_empty_frames


def validate(scene_dict: dict) -> list[Issue]:
def validate(scene_dict: dict, validate_for_empty_frames: bool = True) -> list[Issue]:
"""Validate a scene based on the Deutsche Bahn Requirements.
Parameters
----------
scene_dict : dict
The scene as a dictionary directly from `json.load()` in the raillabel format.
Returns
-------
list[Issue]
list of all requirement errors in the scene. If an empty list is returned, then there are
no errors present and the scene is valid.
Args:
scene_dict: The scene as a dictionary directly from `json.load()` in the raillabel format.
validate_for_empty_frames (optional): If True, the scene is validated for empty frames.
Returns:
List of all requirement errors in the scene. If an empty list is returned, then there are no
errors present and the scene is valid.
"""
schema_errors = validate_schema(scene_dict)
if schema_errors != []:
return schema_errors

scene = Scene.from_json(JSONScene(**scene_dict))
errors = []

errors.extend(validate_schema(scene_dict))
if validate_for_empty_frames:
errors.extend(validate_empty_frames(scene))

return errors
11 changes: 11 additions & 0 deletions tests/validation/test_validate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

import json
import pytest

from raillabel.scene_builder import SceneBuilder

from raillabel_providerkit import validate


Expand All @@ -18,5 +21,13 @@ def test_schema_errors():
assert len(actual) == 1


def test_empty_frame_errors():
scene_dict = json.loads(SceneBuilder.empty().add_frame().result.to_json().model_dump_json())

actual = validate(scene_dict)
assert len(actual) == 1



if __name__ == "__main__":
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])

0 comments on commit 4d415af

Please sign in to comment.