Skip to content
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
9 changes: 9 additions & 0 deletions kiva/celiagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ def set_line_dash(self, lengths, phase=0):
"""
if lengths is not None:
count = len(lengths)
if count % 2 == 1:
raise ValueError(
"Array of lengths should have an even number of values, "
f"got {lengths!r}"
)
if any(length <= 0 for length in lengths):
raise ValueError(
f"All length values should be positive, got {lengths!r}"
)
lengths = np.array(lengths).reshape(count // 2, 2)
else:
lengths = []
Expand Down
10 changes: 10 additions & 0 deletions kiva/tests/test_celiagg_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


class TestCeliaggDrawing(DrawingImageTester, unittest.TestCase):

def create_graphics_context(self, width, height, pixel_scale):
return GraphicsContext((width, height), base_pixel_scale=pixel_scale)

Expand All @@ -37,3 +38,12 @@ def test_ipython_repr_png(self):
with open(filename, 'wb') as fp:
fp.write(stream)
self.assertImageSavedWithContent(filename)

def test_set_line_dash_odd(self):
with self.assertRaises(ValueError):
self.gc.set_line_dash([1.0, 2.0, 3.0])

def test_set_line_dash_positive(self):
# regression test for #909
with self.assertRaises(ValueError):
self.gc.set_line_dash([0.0, 0.0])