Skip to content

Commit

Permalink
feat: validate function
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 20, 2023
1 parent 0078322 commit 578bbfb
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions raillabel_providerkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import format
from .convert import loader_classes
from .convert.convert import convert
from .validation.validate import validate

try:
__version__ = metadata.version("raillabel-providerkit")
Expand Down
35 changes: 35 additions & 0 deletions raillabel_providerkit/validation/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from pathlib import Path

import raillabel

from . import validate_onthology


def validate(scene: raillabel.Scene, onthology: t.Union[dict, Path]) -> t.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.
Returns
-------
list[str]
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.
"""

errors = []

errors += validate_onthology(scene, onthology)

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

import os
import sys
import typing as t
from pathlib import Path
from uuid import uuid4

import pytest
import raillabel

sys.path.append(str(Path(__file__).parent.parent.parent.parent.parent))
from raillabel_providerkit import validate

# == Tests ============================

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


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

0 comments on commit 578bbfb

Please sign in to comment.