From 15b5965e7e5776aabc5d9b20bc25bbb4cd4a702f Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:08:32 +0200 Subject: [PATCH 1/6] chore: upgrade to pre-commit 5 --- .pre-commit-config.yaml | 18 +++++++---------- git-conventional-commits.json | 20 ------------------- git-conventional-commits.json.license | 2 -- .../convert/loader_classes/__init__.py | 2 +- .../_attributes/_attribute_abc.py | 2 +- 5 files changed, 9 insertions(+), 35 deletions(-) delete mode 100644 git-conventional-commits.json delete mode 100644 git-conventional-commits.json.license diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 777347f..a087da8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ default_install_hook_types: [commit-msg, pre-commit] default_stages: [commit, merge-commit] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-ast @@ -26,28 +26,28 @@ repos: - id: fix-byte-order-marker - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 24.10.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/PyCQA/docformatter - rev: v1.5.0 + rev: v1.7.5 hooks: - id: docformatter additional_dependencies: - docformatter[tomli] - repo: https://github.com/PyCQA/pydocstyle - rev: 6.1.1 + rev: 6.3.0 hooks: - id: pydocstyle exclude: '^tests/' additional_dependencies: - pydocstyle[toml] - repo: https://github.com/Lucas-C/pre-commit-hooks - rev: v1.1.13 + rev: v1.5.5 hooks: - id: insert-license name: Insert license headers (shell-style comments) @@ -90,10 +90,6 @@ repos: - --comment-style - '..| |' - repo: https://github.com/fsfe/reuse-tool - rev: v1.0.0 + rev: v4.0.3 hooks: - id: reuse - - repo: https://github.com/qoomon/git-conventional-commits - rev: v2.1.1 - hooks: - - id: conventional-commits diff --git a/git-conventional-commits.json b/git-conventional-commits.json deleted file mode 100644 index 1da947a..0000000 --- a/git-conventional-commits.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "convention" : { - "commitTypes": [ - "build", - "chore", - "ci", - "docs", - "feat", - "fix", - "merge", - "perf", - "refactor", - "revert", - "test", - - "lint" - ], - "commitScopes": [] - } -} diff --git a/git-conventional-commits.json.license b/git-conventional-commits.json.license deleted file mode 100644 index 1b58a49..0000000 --- a/git-conventional-commits.json.license +++ /dev/null @@ -1,2 +0,0 @@ -SPDX-FileCopyrightText: Copyright DB Netz AG and the raillabel-providerkit contributors -SPDX-License-Identifier: Apache-2.0 diff --git a/raillabel_providerkit/convert/loader_classes/__init__.py b/raillabel_providerkit/convert/loader_classes/__init__.py index 2320940..72a3266 100644 --- a/raillabel_providerkit/convert/loader_classes/__init__.py +++ b/raillabel_providerkit/convert/loader_classes/__init__.py @@ -11,7 +11,7 @@ # iterate through the modules in the current package package_dir = str(Path(__file__).resolve().parent) -for (_, module_name, _) in iter_modules([package_dir]): +for _, module_name, _ in iter_modules([package_dir]): # import the module and iterate through its attributes module = import_module(f"{__name__}.{module_name}") diff --git a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_attributes/_attribute_abc.py b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_attributes/_attribute_abc.py index 6edebc5..04e45d6 100644 --- a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_attributes/_attribute_abc.py +++ b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_attributes/_attribute_abc.py @@ -38,7 +38,7 @@ def _collect_attribute_classes(): global ATTRIBUTE_CLASSES package_dir = str(Path(__file__).resolve().parent) - for (_, module_name, _) in iter_modules([package_dir]): + for _, module_name, _ in iter_modules([package_dir]): module = import_module( f"raillabel_providerkit.validation.validate_onthology._onthology_classes._attributes.{module_name}" From 191ca39df369d185cd42f4dd14e70d776ff530f0 Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:11:23 +0200 Subject: [PATCH 2/6] implement _is_frame_empty() --- .../validate_empty_frames/__init__.py | 3 ++ .../validate_empty_frames.py | 26 ++++++++++++ .../test_validate_empty_frames.py | 40 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 raillabel_providerkit/validation/validate_empty_frames/__init__.py create mode 100644 raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py create mode 100644 tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py diff --git a/raillabel_providerkit/validation/validate_empty_frames/__init__.py b/raillabel_providerkit/validation/validate_empty_frames/__init__.py new file mode 100644 index 0000000..3f71fbc --- /dev/null +++ b/raillabel_providerkit/validation/validate_empty_frames/__init__.py @@ -0,0 +1,3 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 +"""Package for validating a scene for empty frames.""" diff --git a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py new file mode 100644 index 0000000..65060e4 --- /dev/null +++ b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py @@ -0,0 +1,26 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +from typing import List + +import raillabel + + +def validate_empty_frames(scene: raillabel.Scene) -> List[str]: + """Validate whether all frames of a scene have at least one annotation. + + Parameters + ---------- + scene : raillabel.Scene + Scene, that should be validated. + + Returns + ------- + list[str] + list of all onthology errors in the scene. If an empty list is returned, then there are no + errors present. + """ + + +def _is_frame_empty(frame: raillabel.format.Frame) -> bool: + return len(frame.annotations) == 0 diff --git a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py new file mode 100644 index 0000000..ec4c146 --- /dev/null +++ b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py @@ -0,0 +1,40 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +import os +import sys +from pathlib import Path + +import pytest +import raillabel + +sys.path.append(str(Path(__file__).parent.parent.parent.parent.parent)) +from raillabel_providerkit.validation.validate_empty_frames.validate_empty_frames import ( + _is_frame_empty, +) + +# == Tests ============================ + +def test_is_frame_empty__true(): + frame = raillabel.format.Frame(uid=0, annotations={}) + assert _is_frame_empty(frame) + +def test_is_frame_empty__false(): + frame = raillabel.format.Frame( + uid=0, annotations={ + "581b0df1-c4cf-4a97-828e-13dd740defe5": raillabel.format.Bbox( + uid=None, + object=None, + sensor=None, + attributes=None, + pos=raillabel.format.Point2d(0, 0), + size=raillabel.format.Size2d(0, 0), + ) + } + ) + assert not _is_frame_empty(frame) + + +if __name__ == "__main__": + os.system("clear") + pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) From 06feba8ed04adea282b8d23bf1e3a513205e4dfe Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:24:02 +0200 Subject: [PATCH 3/6] remove unnecessary lines in tests --- tests/conftest.py | 3 --- .../_util/test_warning.py | 14 +++----------- .../loader_classes/test_loader_understand_ai.py | 6 ------ .../convert/test_convert.py | 3 --- .../format/test_raillabel_v2_schema.py | 1 - .../understand_ai/test_uai_bounding_box_2d.py | 5 ----- .../understand_ai/test_uai_bounding_box_3d.py | 5 ----- .../understand_ai/test_uai_coordinate_system.py | 6 ------ .../format/understand_ai/test_uai_frame.py | 7 ------- .../format/understand_ai/test_uai_metadata.py | 6 ------ .../format/understand_ai/test_uai_point_3d.py | 6 ------ .../format/understand_ai/test_uai_polygon_2d.py | 5 ----- .../format/understand_ai/test_uai_polyline_2d.py | 5 ----- .../format/understand_ai/test_uai_quaternion.py | 6 ------ .../format/understand_ai/test_uai_scene.py | 6 ------ .../understand_ai/test_uai_segmentation_3d.py | 5 ----- .../understand_ai/test_uai_sensor_reference.py | 5 ----- .../format/understand_ai/test_uai_size_3d.py | 6 ------ .../validation/test_validate.py | 9 --------- .../test_validate_empty_frames.py | 6 ------ .../validate_onthology/test_onthology_schema_v1.py | 1 - .../validate_onthology/test_validate_onthology.py | 5 ----- 22 files changed, 3 insertions(+), 118 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f2f58e4..c8d548b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,14 +3,11 @@ import glob import json -import sys import typing as t from pathlib import Path import pytest -sys.path.insert(1, str(Path(__file__).parent.parent)) - json_data_directories = [ Path(__file__).parent / "__test_assets__", Path(__file__).parent.parent / "raillabel_providerkit" / "format" diff --git a/tests/test_raillabel_providerkit/_util/test_warning.py b/tests/test_raillabel_providerkit/_util/test_warning.py index e8d9cbc..5d98cd6 100644 --- a/tests/test_raillabel_providerkit/_util/test_warning.py +++ b/tests/test_raillabel_providerkit/_util/test_warning.py @@ -1,14 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import os -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent)) - from raillabel._util._warning import _warning, _WarningsLogger @@ -21,12 +14,12 @@ def test_issue_warning(): ] def test_handover_exception(): - with pytest.raises(RuntimeError) as error: - with _WarningsLogger() as logger: + with pytest.raises(RuntimeError): + with _WarningsLogger(): raise RuntimeError("weewoo something went wrong") def test_clear_warnings(): - with _WarningsLogger() as logger1: + with _WarningsLogger(): _warning("lorem ipsum") with _WarningsLogger() as logger2: @@ -36,5 +29,4 @@ def test_clear_warnings(): if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) diff --git a/tests/test_raillabel_providerkit/convert/loader_classes/test_loader_understand_ai.py b/tests/test_raillabel_providerkit/convert/loader_classes/test_loader_understand_ai.py index 4eba35c..2d26cd8 100644 --- a/tests/test_raillabel_providerkit/convert/loader_classes/test_loader_understand_ai.py +++ b/tests/test_raillabel_providerkit/convert/loader_classes/test_loader_understand_ai.py @@ -2,13 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 import os -import sys -from pathlib import Path import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel @@ -115,5 +110,4 @@ def test_raillabel_loader_warnings(loader): # Executes the test if the file is called if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear"]) diff --git a/tests/test_raillabel_providerkit/convert/test_convert.py b/tests/test_raillabel_providerkit/convert/test_convert.py index 1184caf..79e8709 100644 --- a/tests/test_raillabel_providerkit/convert/test_convert.py +++ b/tests/test_raillabel_providerkit/convert/test_convert.py @@ -7,8 +7,6 @@ import pytest -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent)) - import raillabel_providerkit @@ -26,5 +24,4 @@ def test_convert_uai_provide_class(json_data): # Executes the test if the file is called if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear"]) diff --git a/tests/test_raillabel_providerkit/format/test_raillabel_v2_schema.py b/tests/test_raillabel_providerkit/format/test_raillabel_v2_schema.py index 83d7baf..ad8102d 100644 --- a/tests/test_raillabel_providerkit/format/test_raillabel_v2_schema.py +++ b/tests/test_raillabel_providerkit/format/test_raillabel_v2_schema.py @@ -30,5 +30,4 @@ def test_sample_data_validation_superschema(json_data): # Executes the test if the file is called if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear"]) diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_2d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_2d.py index be81c2e..16d97e4 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_2d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_2d.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path from uuid import UUID import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel.format.understand_ai._translation import translate_class_id diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_3d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_3d.py index 90b9ff5..5833e8e 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_3d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_bounding_box_3d.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path from uuid import UUID import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel.format.understand_ai._translation import translate_class_id diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_coordinate_system.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_coordinate_system.py index b217928..10afa7d 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_coordinate_system.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_coordinate_system.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_frame.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_frame.py index 6c639aa..4caa59c 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_frame.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_frame.py @@ -1,14 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path -from uuid import UUID - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel._util._warning import _WarningsLogger diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_metadata.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_metadata.py index c7ed6d6..e49ae76 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_metadata.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_metadata.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_point_3d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_point_3d.py index 764c148..a234e22 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_point_3d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_point_3d.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polygon_2d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polygon_2d.py index d1b5bfb..b004c82 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polygon_2d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polygon_2d.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path from uuid import UUID import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel.format.understand_ai._translation import translate_class_id diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polyline_2d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polyline_2d.py index 7655896..5857eb0 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polyline_2d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_polyline_2d.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path from uuid import UUID import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel.format.understand_ai._translation import translate_class_id diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_quaternion.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_quaternion.py index b19c8ed..7ba5b4c 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_quaternion.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_quaternion.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_scene.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_scene.py index 401300f..bdbc825 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_scene.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_scene.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel._util._warning import _WarningsLogger diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_segmentation_3d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_segmentation_3d.py index 2ddde2d..4371fac 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_segmentation_3d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_segmentation_3d.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path from uuid import UUID import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format from raillabel.format.understand_ai._translation import translate_class_id diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_sensor_reference.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_sensor_reference.py index 1bcd210..2b7af86 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_sensor_reference.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_sensor_reference.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys from decimal import Decimal -from pathlib import Path import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_size_3d.py b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_size_3d.py index 680b047..1a5194c 100644 --- a/tests/test_raillabel_providerkit/format/understand_ai/test_uai_size_3d.py +++ b/tests/test_raillabel_providerkit/format/understand_ai/test_uai_size_3d.py @@ -1,13 +1,7 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import sys -from pathlib import Path - import pytest - -sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent)) - import raillabel.format.understand_ai as uai_format # == Fixtures ========================= diff --git a/tests/test_raillabel_providerkit/validation/test_validate.py b/tests/test_raillabel_providerkit/validation/test_validate.py index e3ce73d..126024b 100644 --- a/tests/test_raillabel_providerkit/validation/test_validate.py +++ b/tests/test_raillabel_providerkit/validation/test_validate.py @@ -1,16 +1,8 @@ # 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 ============================ @@ -23,5 +15,4 @@ def test_onthology_errors(demo_onthology, invalid_onthology_scene): if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) diff --git a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py index ec4c146..305f7a5 100644 --- a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py +++ b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py @@ -1,14 +1,9 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -import os -import sys -from pathlib import Path - import pytest import raillabel -sys.path.append(str(Path(__file__).parent.parent.parent.parent.parent)) from raillabel_providerkit.validation.validate_empty_frames.validate_empty_frames import ( _is_frame_empty, ) @@ -36,5 +31,4 @@ def test_is_frame_empty__false(): if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) diff --git a/tests/test_raillabel_providerkit/validation/validate_onthology/test_onthology_schema_v1.py b/tests/test_raillabel_providerkit/validation/validate_onthology/test_onthology_schema_v1.py index 8d9ad12..adaf511 100644 --- a/tests/test_raillabel_providerkit/validation/validate_onthology/test_onthology_schema_v1.py +++ b/tests/test_raillabel_providerkit/validation/validate_onthology/test_onthology_schema_v1.py @@ -193,5 +193,4 @@ def test_sensor_type_attributes(validator): if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) diff --git a/tests/test_raillabel_providerkit/validation/validate_onthology/test_validate_onthology.py b/tests/test_raillabel_providerkit/validation/validate_onthology/test_validate_onthology.py index 53baa7f..926a26d 100644 --- a/tests/test_raillabel_providerkit/validation/validate_onthology/test_validate_onthology.py +++ b/tests/test_raillabel_providerkit/validation/validate_onthology/test_validate_onthology.py @@ -1,16 +1,12 @@ # 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 exceptions from raillabel_providerkit.validation import validate_onthology @@ -730,5 +726,4 @@ def test_invalid_sensor_type_attributes_and_attributes(sensors, object_person): if __name__ == "__main__": - os.system("clear") pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) From 8945f532d6b8ff110b1f054a4e032fca19046581 Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:35:41 +0200 Subject: [PATCH 4/6] extract empty annotation creation --- tests/conftest.py | 16 ++++++++++++++++ .../test_validate_empty_frames.py | 15 ++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c8d548b..7529a61 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ from pathlib import Path import pytest +import raillabel json_data_directories = [ Path(__file__).parent / "__test_assets__", @@ -65,3 +66,18 @@ def _load_json_data(path: Path) -> dict: with path.open() as f: json_data = json.load(f) return json_data + +@pytest.fixture +def empty_annotation() -> raillabel.format.Bbox: + """Return a minimal possible annotation.""" + return raillabel.format.Bbox( + uid="1f654afe-0a18-497f-9db8-afac360ce94c", + object=raillabel.format.Object( + uid="7df959d7-0ec2-4722-8b62-bb2e529de2ec", + name="person0000", + type="person", + ), + sensor=None, + pos=raillabel.format.Point2d(0.0, 0.0), + size=raillabel.format.Size2d(0.0, 0.0), + ) diff --git a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py index 305f7a5..42a8e55 100644 --- a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py +++ b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py @@ -8,23 +8,16 @@ _is_frame_empty, ) -# == Tests ============================ def test_is_frame_empty__true(): frame = raillabel.format.Frame(uid=0, annotations={}) assert _is_frame_empty(frame) -def test_is_frame_empty__false(): +def test_is_frame_empty__false(empty_annotation): frame = raillabel.format.Frame( - uid=0, annotations={ - "581b0df1-c4cf-4a97-828e-13dd740defe5": raillabel.format.Bbox( - uid=None, - object=None, - sensor=None, - attributes=None, - pos=raillabel.format.Point2d(0, 0), - size=raillabel.format.Size2d(0, 0), - ) + uid=0, + annotations={ + "581b0df1-c4cf-4a97-828e-13dd740defe5": empty_annotation } ) assert not _is_frame_empty(frame) From a4cf07800ff11ad168ae3fccc98b7493b5e16baa Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:59:17 +0200 Subject: [PATCH 5/6] set up validate_empty_frames tests --- tests/conftest.py | 32 ++++++++++- .../test_validate_empty_frames.py | 53 ++++++++++++++++--- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7529a61..bc49225 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,9 +67,39 @@ def _load_json_data(path: Path) -> dict: json_data = json.load(f) return json_data +@pytest.fixture +def empty_scene() -> raillabel.Scene: + return raillabel.Scene( + metadata=raillabel.format.Metadata(schema_version="1.0.0"), + sensors={}, + objects={}, + frames={}, + ) + +@pytest.fixture +def default_frame(empty_annotation) -> raillabel.format.Frame: + return raillabel.format.Frame( + uid=0, + timestamp=None, + sensors={}, + frame_data={}, + annotations={ + "0fb4fc0b-3eeb-443a-8dd0-2caf9912d016": empty_annotation + } + ) + +@pytest.fixture +def empty_frame() -> raillabel.format.Frame: + return raillabel.format.Frame( + uid=0, + timestamp=None, + sensors={}, + frame_data={}, + annotations={} + ) + @pytest.fixture def empty_annotation() -> raillabel.format.Bbox: - """Return a minimal possible annotation.""" return raillabel.format.Bbox( uid="1f654afe-0a18-497f-9db8-afac360ce94c", object=raillabel.format.Object( diff --git a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py index 42a8e55..b0c5274 100644 --- a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py +++ b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py @@ -6,6 +6,7 @@ from raillabel_providerkit.validation.validate_empty_frames.validate_empty_frames import ( _is_frame_empty, + validate_empty_frames, ) @@ -13,15 +14,53 @@ def test_is_frame_empty__true(): frame = raillabel.format.Frame(uid=0, annotations={}) assert _is_frame_empty(frame) -def test_is_frame_empty__false(empty_annotation): - frame = raillabel.format.Frame( - uid=0, - annotations={ - "581b0df1-c4cf-4a97-828e-13dd740defe5": empty_annotation - } - ) +def test_is_frame_empty__false(empty_annotation, empty_frame): + frame = empty_frame + frame.annotations["581b0df1-c4cf-4a97-828e-13dd740defe5"] = empty_annotation + assert not _is_frame_empty(frame) +def test_validate_empty_frames__no_error(default_frame, empty_scene): + scene = empty_scene + scene.frames = { + 0: default_frame, + 1: default_frame, + 2: default_frame, + } + + assert len(validate_empty_frames(scene)) == 0 + +def test_validate_empty_frames__one_error(default_frame, empty_frame, empty_scene): + scene = empty_scene + scene.frames = { + 0: default_frame, + 1: empty_frame, + 2: default_frame, + } + + assert len(validate_empty_frames(scene)) == 1 + +def test_validate_empty_frames__two_errors(default_frame, empty_frame, empty_scene): + scene = empty_scene + scene.frames = { + 0: empty_frame, + 1: default_frame, + 2: empty_frame, + } + + assert len(validate_empty_frames(scene)) == 2 + +def test_validate_empty_frames__error_message_contains_indentifying_info(empty_frame, empty_scene): + scene = empty_scene + scene.frames = { + 0: empty_frame, + } + + error_message = validate_empty_frames(scene)[0].lower() + assert "frame" in error_message + assert "0" in error_message + assert "empty" in error_message or "no annotations" in error_message + if __name__ == "__main__": pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"]) From e7f5b1360bd6af0fa58b3461d06e6c77d79a1541 Mon Sep 17 00:00:00 2001 From: Niklas Freund Date: Fri, 25 Oct 2024 11:06:32 +0200 Subject: [PATCH 6/6] feat: Implement validate_empty_frames --- .../validate_empty_frames/validate_empty_frames.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py index 65060e4..1bdc2e9 100644 --- a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py +++ b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py @@ -17,9 +17,16 @@ def validate_empty_frames(scene: raillabel.Scene) -> List[str]: Returns ------- list[str] - list of all onthology errors in the scene. If an empty list is returned, then there are no + list of all empty frame errors in the scene. If an empty list is returned, then there are no errors present. """ + errors: List[str] = [] + + for frame_uid, frame in scene.frames.items(): + if _is_frame_empty(frame): + errors.append("Frame " + str(frame_uid) + " has no annotations!") + + return errors def _is_frame_empty(frame: raillabel.format.Frame) -> bool: