Skip to content

Commit

Permalink
set up validate_empty_frames tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 21, 2024
1 parent 8945f53 commit a4cf078
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
32 changes: 31 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,61 @@

from raillabel_providerkit.validation.validate_empty_frames.validate_empty_frames import (
_is_frame_empty,
validate_empty_frames,
)


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"])

0 comments on commit a4cf078

Please sign in to comment.