Skip to content

Commit 6d158bd

Browse files
Enhance Flatten layout handling: update image computation to handle None outputs and add unit test for empty layout scenario.
1 parent 27669f5 commit 6d158bd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

model_api/python/model_api/visualizer/layout.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ def __init__(self, *args: Type[Primitive]) -> None:
4545
def __call__(self, scene: Scene) -> PIL.Image:
4646
_image: PIL.Image = scene.base.copy()
4747
for child in self.children:
48-
_image = self._compute_on_primitive(child, _image, scene)
48+
output = self._compute_on_primitive(child, _image, scene)
49+
if output is not None:
50+
_image = output
4951
return _image

tests/python/unit/visualizer/test_layout.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ def test_flatten_layout(mock_image: Image, mock_scene: Scene):
1919
expected_image = Image.blend(mock_image, overlay, 0.4)
2020
mock_scene.layout = Flatten(Overlay)
2121
assert mock_scene.render() == expected_image
22+
23+
24+
def test_flatten_layout_with_no_primitives(mock_image: Image, mock_scene: Scene):
25+
"""Test if the layout is created correctly."""
26+
mock_scene.layout = Flatten()
27+
assert mock_scene.render() == mock_image

0 commit comments

Comments
 (0)