Skip to content

Commit

Permalink
Merge branch '158-getter-for-corner-annotations'
Browse files Browse the repository at this point in the history
  • Loading branch information
MattClarkson committed Oct 23, 2020
2 parents 7801f2f + cffe0bc commit 60b93ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
13 changes: 12 additions & 1 deletion sksurgeryvtk/text/text_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self):
self.text_actor = vtk.vtkCornerAnnotation()

def set_text(self, text_list):
"""Set the text in each of the four corners
"""
Set the text in each of the four corners
:param text_list: Text to display.
[bottom-left, bottom-right, top-left, top-right].
Expand All @@ -38,6 +39,16 @@ def set_text(self, text_list):
for idx, item in enumerate(text_list):
self.text_actor.SetText(idx, item)

def get_text(self):
"""
Returns the current list of text annotations
:return: [bottom-left, bottom-right, top-left, top-right]
"""
return [self.text_actor.GetText(0),
self.text_actor.GetText(1),
self.text_actor.GetText(2),
self.text_actor.GetText(3)]

def set_text_on_top_left(self, text):
"""
Set the text on the top-left corner.
Expand Down
26 changes: 25 additions & 1 deletion tests/text/test_corner_annotaiton.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,46 @@ def corner_annotaiton():
corner_annotaiton = VTKCornerAnnotation()
return corner_annotaiton


def test_non_list_input_raises_error(corner_annotaiton):
invalid_input = 1
with pytest.raises(TypeError):
corner_annotaiton.set_text(invalid_input)


def test_invalid_size_input_raises_error(corner_annotaiton):
invalid_input = ["1", "2", "3"]
with pytest.raises(ValueError):
corner_annotaiton.set_text(invalid_input)


def test_non_string_in_list_raises_error(corner_annotaiton):
invalid_input = ["1", "2", 3, "4"]
with pytest.raises(ValueError):
corner_annotaiton.set_text(invalid_input)


def test_none_in_list_raises_error(corner_annotaiton):
invalid_input = ["1", "2", None, "4"]
with pytest.raises(ValueError):
corner_annotaiton.set_text(invalid_input)


def test_valid_input_raises_no_error(corner_annotaiton):

valid_input = ["1", "2", "3", "4"]
corner_annotaiton.set_text(valid_input)
corner_annotaiton.set_text(valid_input)


def test_setter_getter(corner_annotaiton):

initial = corner_annotaiton.get_text()
assert len(initial) == 4
assert initial[0] is None
assert initial[1] is None
assert initial[2] is None
assert initial[3] is None
stuff_to_set = ['Snappy', 'is', 'totally', 'awesome']
corner_annotaiton.set_text(stuff_to_set)
stuff_retrieved = corner_annotaiton.get_text()
assert stuff_to_set == stuff_retrieved

0 comments on commit 60b93ff

Please sign in to comment.