From 043c4bee1ce94624990f5c450dace20d1dd29db6 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Thu, 15 Aug 2019 17:43:49 -0700 Subject: [PATCH] Select tests --- clusterview/opengl_widget.py | 4 ---- clusterview/points.py | 7 +++++++ tests/test_point_set.py | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/clusterview/opengl_widget.py b/clusterview/opengl_widget.py index 9d0458d..dbfd071 100644 --- a/clusterview/opengl_widget.py +++ b/clusterview/opengl_widget.py @@ -307,10 +307,6 @@ def highlight_selection(): Given the current move bounding box, highlights any points inside it. """ - # TODO: There's an edge case here - # The edge case is that if you click and drag up top_left becomes - # bottom right so there must be a condition where they should be - # swapped. top_left = get_bb_top_left() bottom_right = get_bb_bottom_right() diff --git a/clusterview/points.py b/clusterview/points.py index 25bdb38..33e2ab5 100644 --- a/clusterview/points.py +++ b/clusterview/points.py @@ -145,6 +145,13 @@ class PointSet: def point_size(self): return self.__point_size + def clear_selection(self): + """ + Handy helper function to clear all selected points. + """ + for p in self.__points: + p.unselect() + def add_point(self, x, y, attrs=[]): """ Adds a point in screen coordinates and an optional attribute to diff --git a/tests/test_point_set.py b/tests/test_point_set.py index a5c31c4..adc7997 100644 --- a/tests/test_point_set.py +++ b/tests/test_point_set.py @@ -83,3 +83,30 @@ def test_attributes_must_be_array_of_attributes(): with pytest.raises(ValueError): l = PointSet(8) l.add_point(1, 2, attrs=[1,2,3,4,5]) + + +def test_clear_all_selected_points(): + l = PointSet(8) + l.add_point(1, 2) + l.add_point(3, 4) + + for p in l.points: + p.select() + + selected = 0 + + for p in l.points: + if p.selected: + selected += 1 + + assert selected == 2 + + l.clear_selection() + + unselected = 0 + + for p in l.points: + if not p.selected: + unselected += 1 + + assert unselected == 2