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

Raise type error for the unsupported object type #149

Merged
merged 6 commits into from
Jul 13, 2021
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
11 changes: 10 additions & 1 deletion paz/processors/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ def __init__(self, class_names=None, colors=None,
self.colors = colors
self.weighted = weighted
self.scale = scale

if (self.class_names is not None and
not isinstance(self.class_names, list)):
raise TypeError("Class name should be of type 'List of strings'")

if (self.colors is not None and
not all(isinstance(color, list) for color in self.colors)):
raise TypeError("Colors should be of type 'List of lists'")

if self.colors is None:
self.colors = lincolor(len(self.class_names))

if class_names is not None:
if self.class_names is not None:
self.class_to_color = dict(zip(self.class_names, self.colors))
else:
self.class_to_color = {None: self.colors, '': self.colors}
Expand Down
16 changes: 16 additions & 0 deletions tests/paz/processors/draw_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from paz import processors as pr


def test_DrawBoxes2D_with_invalid_class_names_type():
with pytest.raises(TypeError):
class_names = 'Face'
colors = [[255, 0, 0]]
pr.DrawBoxes2D(class_names, colors)


def test_DrawBoxes2D_with_invalid_colors_type():
with pytest.raises(TypeError):
class_names = ['Face']
colors = [255, 0, 0]
pr.DrawBoxes2D(class_names, colors)