Repository: MyreMylar/pygame_gui
Pull request #296 (2022-08-06 09:46:35)

More element coverage fixes & bug fix for selection list
Basically default selecting 'off-screen' list items no longer asserts


Patch:
diff --git a/pygame_gui/elements/ui_selection_list.py b/pygame_gui/elements/ui_selection_list.py
index 4a43638..d075ef6 100644
--- a/pygame_gui/elements/ui_selection_list.py
+++ b/pygame_gui/elements/ui_selection_list.py
@@ -375,7 +375,8 @@ class UISelectionList(UIElement):
             if idx is None:
                 raise ValueError(f'Requested default {d} not found in selection list {self.item_list}.')
             self.item_list[idx]['selected'] = True
-            self.item_list[idx]['button_element'].select()
+            if self.item_list[idx]['button_element'] is not None:
+                self.item_list[idx]['button_element'].select()
 
     def process_event(self, event: pygame.event.Event) -> bool:
         """


Test patch:
diff --git a/tests/test_elements/test_ui_horizontal_slider.py b/tests/test_elements/test_ui_horizontal_slider.py
index 9edb3fb..6fdc9e9 100644
--- a/tests/test_elements/test_ui_horizontal_slider.py
+++ b/tests/test_elements/test_ui_horizontal_slider.py
@@ -82,11 +82,14 @@ class TestUIHorizontalSlider:
         slider.update(0.01)
         slider.update(0.01)
         slider.update(0.5)
+        slider.update(0.5)
         slider.left_button.held = False
+        slider.button_held_repeat_acc = 0.0
         slider.right_button.held = True
         slider.update(0.01)
         slider.update(0.01)
         slider.update(0.5)
+        slider.update(0.5)
 
         assert slider.has_moved_recently is True
 
diff --git a/tests/test_elements/test_ui_label.py b/tests/test_elements/test_ui_label.py
index 63b892c..18e28c2 100644
--- a/tests/test_elements/test_ui_label.py
+++ b/tests/test_elements/test_ui_label.py
@@ -242,6 +242,15 @@ class TestUILabel:
 
         assert label.image is not None
 
+    def test_get_objectID(self, _init_pygame, default_ui_manager,
+                          _display_surface_return_none):
+        label = UILabel(relative_rect=pygame.Rect(100, 100, 150, 30),
+                        text="Test Label",
+                        manager=default_ui_manager,
+                        object_id="#test_label")
+
+        assert label.get_object_id() == "#test_label"
+
 
 if __name__ == '__main__':
     pytest.console_main()
diff --git a/tests/test_elements/test_ui_selection_list.py b/tests/test_elements/test_ui_selection_list.py
index 1cf9608..a2acdd6 100644
--- a/tests/test_elements/test_ui_selection_list.py
+++ b/tests/test_elements/test_ui_selection_list.py
@@ -108,6 +108,7 @@ class TestUISelectionList:
                                                     'item 9', 'item 10', 'item 11', 'item 12',
                                                     'item 13', 'item 14', 'item 15', 'item 16'],
                                          manager=default_ui_manager,
+                                         default_selection=['item 7'],
                                          allow_multi_select=True)
 
         assert selection_list.scroll_bar is not None
diff --git a/tests/test_elements/test_ui_window.py b/tests/test_elements/test_ui_window.py
index e215c70..c002e9d 100644
--- a/tests/test_elements/test_ui_window.py
+++ b/tests/test_elements/test_ui_window.py
@@ -231,6 +231,10 @@ class TestUIWindow:
         window.edge_hovering[3] = True
         window.update(time_delta=0.05)
 
+        window.start_resize_rect = pygame.Rect(0, 0, 190, 190)
+        default_ui_manager.mouse_position = (25, 25)
+        window.update(time_delta=0.05)
+
     def test_check_hover(self, _init_pygame, default_ui_manager: UIManager,
                          _display_surface_return_none: None):
         window = UIWindow(pygame.Rect(100, 100, 200, 200), window_display_title="Test Window",
@@ -591,14 +595,17 @@ class TestUIWindow:
         assert compare_surfaces(empty_surface, surface)
 
     def test_get_relative_mouse_pos(self, _init_pygame, default_ui_manager,
-                                 _display_surface_return_none):
+                                    _display_surface_return_none):
         window = UIWindow(pygame.Rect(100, 100, 400, 400),
                           window_display_title="Test Window",
                           manager=default_ui_manager,
                           visible=0)
 
-        result = window.get_relative_mouse_pos()
-        assert result is None
+        default_ui_manager.mouse_position = (0, 0)
+        assert window.get_relative_mouse_pos() is None
+
+        default_ui_manager.mouse_position = (200, 200)
+        assert window.get_relative_mouse_pos() == (84, 57)
 
 
 if __name__ == '__main__':