Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement validate_empty_frames #3

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
20 changes: 0 additions & 20 deletions git-conventional-commits.json

This file was deleted.

2 changes: 0 additions & 2 deletions git-conventional-commits.json.license

This file was deleted.

2 changes: 1 addition & 1 deletion raillabel_providerkit/convert/loader_classes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Package for validating a scene for empty frames."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 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:
return len(frame.annotations) == 0
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
49 changes: 46 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +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))
import raillabel

json_data_directories = [
Path(__file__).parent / "__test_assets__",
Expand Down Expand Up @@ -68,3 +66,48 @@ def _load_json_data(path: Path) -> dict:
with path.open() as f:
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 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),
)
14 changes: 3 additions & 11 deletions tests/test_raillabel_providerkit/_util/test_warning.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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:
Expand All @@ -36,5 +29,4 @@ def test_clear_warnings():


if __name__ == "__main__":
os.system("clear")
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"])
3 changes: 0 additions & 3 deletions tests/test_raillabel_providerkit/convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import pytest

sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent))

import raillabel_providerkit


Expand All @@ -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"])
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 =========================
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 =========================
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =========================
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading
Loading