Skip to content

Commit

Permalink
feat: validate_schema in validate
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Nov 25, 2024
1 parent 32f8ddf commit 71703d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
21 changes: 8 additions & 13 deletions raillabel_providerkit/validation/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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
14 changes: 8 additions & 6 deletions tests/test_raillabel_providerkit/validation/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down

0 comments on commit 71703d5

Please sign in to comment.