Repository: MyreMylar/pygame_gui
Pull request #287 (2022-08-02 18:57:51)

A series of small testing coverage improvements
Also a minor typing fix for UIManager set_active_cursor


Patch:
diff --git a/pygame_gui/ui_manager.py b/pygame_gui/ui_manager.py
index 4ef6bfe..b69bab4 100644
--- a/pygame_gui/ui_manager.py
+++ b/pygame_gui/ui_manager.py
@@ -93,7 +93,7 @@ class UIManager(IUIManagerInterface):
 
         self.resizing_window_cursors = None
         self._load_default_cursors()
-        self.active_user_cursor = pygame.SYSTEM_CURSOR_ARROW
+        self.active_user_cursor = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW)
         self._active_cursor = self.active_user_cursor
         self.text_input_hovered = False
 
@@ -270,7 +270,7 @@ class UIManager(IUIManagerInterface):
 
         # handle mouse cursors
         if self.text_input_hovered:
-            new_cursor = pygame.SYSTEM_CURSOR_IBEAM
+            new_cursor = pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_IBEAM)
             if new_cursor != self._active_cursor:
                 self._active_cursor = new_cursor
                 try:
@@ -487,17 +487,14 @@ class UIManager(IUIManagerInterface):
                     print(str(element.most_specific_combined_id))
             print(' ')
 
-    def set_active_cursor(self, cursor: Tuple[Tuple[int, int], Tuple[int, int],
-                                              Tuple[int, ...], Tuple[int, ...]]):
+    def set_active_cursor(self, cursor: pygame.cursors.Cursor):
         """
         This is for users of the library to set the currently active cursor, it will be currently
         only be overridden by the resizing cursors.
 
-        The expected input is in the same format as the standard pygame cursor module, except
-        without expanding the initial Tuple. So, to call this function with the default pygame
-        arrow cursor you would do::
+        The expected input is a pygame.cursors.Cursor::
 
-            manager.set_active_cursor(pygame.SYSTEM_CURSOR_ARROW)
+            manager.set_active_cursor(pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_ARROW))
 
         """
 
@@ -548,12 +545,12 @@ class UIManager(IUIManagerInterface):
 
         """
         # cursors for resizing windows
-        self.resizing_window_cursors = {'xl': pygame.SYSTEM_CURSOR_SIZEWE,
-                                        'xr': pygame.SYSTEM_CURSOR_SIZEWE,
-                                        'yt': pygame.SYSTEM_CURSOR_SIZENS,
-                                        'yb': pygame.SYSTEM_CURSOR_SIZENS,
-                                        'xy': pygame.SYSTEM_CURSOR_SIZENWSE,
-                                        'yx': pygame.SYSTEM_CURSOR_SIZENESW}
+        self.resizing_window_cursors = {'xl': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZEWE),
+                                        'xr': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZEWE),
+                                        'yt': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZENS),
+                                        'yb': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZENS),
+                                        'xy': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZENWSE),
+                                        'yx': pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_SIZENESW)}
 
     def set_locale(self, locale: str):
         self._locale = locale


Test patch:
diff --git a/tests/test_constants.py b/tests/test_constants.py
new file mode 100644
index 0000000..8aa2464
--- /dev/null
+++ b/tests/test_constants.py
@@ -0,0 +1,23 @@
+import pytest
+
+from pygame_gui import UITextEffectType
+
+
+class TestConstants:
+    """
+    Testing the Constants
+    """
+
+    def test_ui_text_effect_type(self):
+        text_effect_type = UITextEffectType("test")
+
+        assert "basic " + text_effect_type == "basic test"
+        assert text_effect_type + " this" == "test this"
+        assert text_effect_type == "test"
+        assert text_effect_type != 5
+
+        with pytest.raises(AttributeError):
+            5 + text_effect_type
+
+        with pytest.raises(AttributeError):
+            text_effect_type + 5
diff --git a/tests/test_core/test_shadow_generator.py b/tests/test_core/test_shadow_generator.py
index 71ec1ea..a08662b 100644
--- a/tests/test_core/test_shadow_generator.py
+++ b/tests/test_core/test_shadow_generator.py
@@ -8,6 +8,12 @@ class TestShadowGenerator:
     def test_creation(self, _init_pygame):
         ShadowGenerator()
 
+    def test_clear_short_term_caches(self, _init_pygame):
+        generator = ShadowGenerator()
+        generator.clear_short_term_caches()
+
+        assert generator.short_term_rect_cache == {}
+
     def test_find_closest_shadow_scale_to_size_invalid(self, _init_pygame):
         generator = ShadowGenerator()
         assert generator.find_closest_shadow_scale_to_size(size=(100, 100), shape='triangle') is None
diff --git a/tests/test_pyinstaller_hook.py b/tests/test_pyinstaller_hook.py
new file mode 100644
index 0000000..60dbc46
--- /dev/null
+++ b/tests/test_pyinstaller_hook.py
@@ -0,0 +1,15 @@
+import os
+import pytest
+import importlib
+
+from pygame_gui.__pyinstaller import get_hook_dirs
+importlib.import_module("pygame_gui.__pyinstaller.hook-pygame_gui")
+
+
+class TestPyInstallerHook:
+    """
+    Testing the PyInstaller Hook
+    """
+
+    def test_get_hooks_dir(self):
+        assert os.path.basename(os.path.normpath(get_hook_dirs()[0])) == "__pyinstaller"
diff --git a/tests/test_ui_manager.py b/tests/test_ui_manager.py
index 038ef86..08f8f06 100644
--- a/tests/test_ui_manager.py
+++ b/tests/test_ui_manager.py
@@ -3,8 +3,6 @@ import platform
 import pygame
 import pytest
 
-from pygame_gui import UI_BUTTON_PRESSED
-from pygame_gui._constants import OldType
 from pygame_gui.ui_manager import UIManager
 from pygame_gui.core import UIAppearanceTheme, UIWindowStack
 from pygame_gui.elements.ui_button import UIButton
@@ -327,6 +325,25 @@ class TestUIManager:
 
         assert manager.visual_debug_active is False
 
+    def test_set_active_cursor(self, _init_pygame, _display_surface_return_none):
+        manager = UIManager((800, 600))
+        manager.set_active_cursor(pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_HAND))
+
+        manager.update(0.5)
+
+        assert manager._active_cursor == pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_HAND)
+
+    def test_set_hovering_text(self, _init_pygame, _display_surface_return_none):
+        manager = UIManager((800, 600))
+
+        manager.set_text_input_hovered(True)
+
+        manager.update(0.5)
+        assert manager._active_cursor == pygame.cursors.Cursor(pygame.SYSTEM_CURSOR_IBEAM)
+
+    def test_translation_dir_path(self):
+        manager = UIManager((800, 600), translation_directory_paths=['pygame_gui/data/translations/'])
+
 
 if __name__ == '__main__':
     pytest.console_main()
diff --git a/tests/test_windows/test_ui_colour_picker_dialog.py b/tests/test_windows/test_ui_colour_picker_dialog.py
index d277cb0..d089d2a 100644
--- a/tests/test_windows/test_ui_colour_picker_dialog.py
+++ b/tests/test_windows/test_ui_colour_picker_dialog.py
@@ -349,6 +349,35 @@ class TestUIColourPickerDialog:
                     event.ui_element == colour_picker.red_channel):
                 confirm_event_fired = True
 
+            default_ui_manager.process_events(event)
+
+        assert confirm_event_fired
+
+        colour_picker.hue_channel.entry.set_text('512')
+        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN,
+                                                             {'button': pygame.BUTTON_LEFT,
+                                                              'pos': colour_picker.hue_channel.entry.rect.center}
+                                                             ))
+        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONUP,
+                                                             {'button': pygame.BUTTON_LEFT,
+                                                              'pos': colour_picker.hue_channel.entry.rect.center}
+                                                             ))
+        default_ui_manager.process_events(pygame.event.Event(pygame.KEYDOWN,
+                                                             {'key': pygame.K_RETURN}
+                                                             ))
+
+        for event in pygame.event.get():
+            default_ui_manager.process_events(event)
+
+        confirm_event_fired = False
+        for event in pygame.event.get():
+
+            if (event.type == pygame_gui.UI_COLOUR_PICKER_COLOUR_CHANNEL_CHANGED and
+                    event.ui_element == colour_picker.hue_channel):
+                confirm_event_fired = True
+
+            default_ui_manager.process_events(event)
+
         assert confirm_event_fired
 
     def test_update_saturation_value_square(self, _init_pygame, default_ui_manager, _display_surface_return_none):
diff --git a/tests/test_windows/test_ui_console_window.py b/tests/test_windows/test_ui_console_window.py
index 986d067..5e55b72 100644
--- a/tests/test_windows/test_ui_console_window.py
+++ b/tests/test_windows/test_ui_console_window.py
@@ -285,6 +285,21 @@ class TestUIConsoleWindow:
 
         assert console_window.command_entry.get_text() == 'A second command'
 
+    def test_clear_log(self, _init_pygame, default_ui_manager,
+                       _display_surface_return_none):
+        console_window = UIConsoleWindow(rect=pygame.rect.Rect((0, 0), (700, 500)),
+                                         manager=default_ui_manager)
+
+        console_window.command_entry.set_text('<b>A line of text to log</b>')
+
+        console_window.add_output_line_to_log('line to add')
+
+        console_window.clear_log()
+
+        assert console_window.logged_commands_above == []
+        assert console_window.current_logged_command is None
+        assert console_window.logged_commands_below == []
+
 
 if __name__ == '__main__':
     pytest.console_main()