From 71703d57a655a097dc48e029fa24389c2ed13d70 Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 25 Nov 2024 16:03:58 +0100 Subject: [PATCH] feat: validate_schema in validate --- raillabel_providerkit/validation/validate.py | 21 +++++++------------ .../validation/test_validate.py | 14 +++++++------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/raillabel_providerkit/validation/validate.py b/raillabel_providerkit/validation/validate.py index 2933b70..f2c8b72 100644 --- a/raillabel_providerkit/validation/validate.py +++ b/raillabel_providerkit/validation/validate.py @@ -3,24 +3,16 @@ from __future__ import annotations -from pathlib import Path +from . import validate_schema -import raillabel -from . import validate_onthology - - -def validate(scene: raillabel.Scene, onthology: dict | Path) -> list[str]: +def validate(scene_dict: dict) -> list[str]: """Validate a scene based on the Deutsche Bahn Requirements. Parameters ---------- - scene : raillabel.Scene - The scene containing the annotations. - onthology : dict or Path - Onthology YAML-data or file containing a information about all classes and their - attributes. The onthology must adhere to the onthology_schema. If a path is provided, the - file is loaded as a YAML. + scene_dict : dict + The scene as a dictionary directly from `json.load()` in the raillabel format. Returns ------- @@ -31,6 +23,9 @@ def validate(scene: raillabel.Scene, onthology: dict | Path) -> list[str]: """ errors = [] - errors += validate_onthology(scene, onthology) + errors.extend(validate_schema(scene_dict)) + + if len(errors) > 0: + return errors return errors diff --git a/tests/test_raillabel_providerkit/validation/test_validate.py b/tests/test_raillabel_providerkit/validation/test_validate.py index 0ac5b60..ee5c160 100644 --- a/tests/test_raillabel_providerkit/validation/test_validate.py +++ b/tests/test_raillabel_providerkit/validation/test_validate.py @@ -5,15 +5,17 @@ from raillabel_providerkit import validate -# == Tests ============================ +def test_no_errors_in_empty_scene(): + scene_dict = {"openlabel": {"metadata": {"schema_version": "1.0.0"}}} + actual = validate(scene_dict) + assert len(actual) == 0 -def test_no_errors(demo_onthology, valid_onthology_scene): - assert validate(valid_onthology_scene, demo_onthology) == [] - -def test_onthology_errors(demo_onthology, invalid_onthology_scene): - assert len(validate(invalid_onthology_scene, demo_onthology)) == 1 +def test_schema_errors(): + scene_dict = {"openlabel": {}} + actual = validate(scene_dict) + assert len(actual) == 1 if __name__ == "__main__":