Skip to content

Commit

Permalink
Merge pull request #149 from proneetsharma/master
Browse files Browse the repository at this point in the history
Raise type error for the unsupported object type
  • Loading branch information
oarriaga authored Jul 13, 2021
2 parents 5f96305 + d63f2af commit 98282f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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)

0 comments on commit 98282f2

Please sign in to comment.