From a4cf07800ff11ad168ae3fccc98b7493b5e16baa Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 21 Oct 2024 13:59:17 +0200 Subject: [PATCH] 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"])