diff --git a/pyproject.toml b/pyproject.toml index 25d1fcd..52c0c7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/raillabel_providerkit/validation/__init__.py b/raillabel_providerkit/validation/__init__.py index d33d953..1946dfa 100644 --- a/raillabel_providerkit/validation/__init__.py +++ b/raillabel_providerkit/validation/__init__.py @@ -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 diff --git a/raillabel_providerkit/validation/validate.py b/raillabel_providerkit/validation/validate.py index 1b111f4..1095a7e 100644 --- a/raillabel_providerkit/validation/validate.py +++ b/raillabel_providerkit/validation/validate.py @@ -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 diff --git a/tests/validation/test_validate.py b/tests/validation/test_validate.py index ee5c160..48629ca 100644 --- a/tests/validation/test_validate.py +++ b/tests/validation/test_validate.py @@ -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 @@ -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"])