Repository: MyreMylar/pygame_gui
Pull request #310 (2022-08-11 21:12:31)

Improve text coverage again


Patch:
diff --git a/pygame_gui/core/text/text_effects.py b/pygame_gui/core/text/text_effects.py
index 1769783..f5a8031 100644
--- a/pygame_gui/core/text/text_effects.py
+++ b/pygame_gui/core/text/text_effects.py
@@ -318,8 +318,8 @@ class BounceEffect(TextEffect):
 
         :param time_delta: time in seconds since last frame.
         """
+        self.time_acc += time_delta
         if self.time_acc < self.time_to_complete_bounce:
-            self.time_acc += time_delta
 
             bounce_progress = self.time_acc / max(self.time_to_complete_bounce, 0.000001)
             if bounce_progress < 0.5:
@@ -404,9 +404,8 @@ class TiltEffect(TextEffect):
 
         :param time_delta: time in seconds since last frame.
         """
+        self.time_acc += time_delta
         if self.time_acc < self.time_to_complete_rotation:
-            self.time_acc += time_delta
-
             spin_progress = self.time_acc / max(self.time_to_complete_rotation, 0.000001)
             if spin_progress < 0.5:
                 current_rotation = int(((spin_progress * 2) ** 2) * self.max_rotation)
@@ -490,8 +489,8 @@ class ExpandContractEffect(TextEffect):
 
         :param time_delta: time in seconds since last frame.
         """
+        self.time_acc += time_delta
         if self.time_acc < self.time_to_complete_expand_contract:
-            self.time_acc += time_delta
 
             scale_progress = self.time_acc / max(self.time_to_complete_expand_contract, 0.000001)
             if scale_progress < 0.5:


Test patch:
diff --git a/tests/test_core/test_text/test_html_parser.py b/tests/test_core/test_text/test_html_parser.py
index 8fc936c..7b5802e 100644
--- a/tests/test_core/test_text/test_html_parser.py
+++ b/tests/test_core/test_text/test_html_parser.py
@@ -73,6 +73,10 @@ class TestHTMLParser:
 
         assert parser.current_style['font_size'] is None
 
+        parser.handle_starttag(tag='font', attrs=[('size', "")])
+
+        assert parser.current_style['font_size'] is None
+
         with pytest.warns(UserWarning, match="not a supported html style size"):
             parser.handle_starttag(tag='font', attrs=[('size', "8")])
 
diff --git a/tests/test_core/test_text/test_text_box_layout_row.py b/tests/test_core/test_text/test_text_box_layout_row.py
index b06c066..98b33c3 100644
--- a/tests/test_core/test_text/test_text_box_layout_row.py
+++ b/tests/test_core/test_text/test_text_box_layout_row.py
@@ -485,6 +485,11 @@ class TestTextBoxLayoutRow:
 
         assert layout_row.cursor_index == 4
 
+        layout_row.set_cursor_from_click_pos((-1, 5))
+
+        assert layout_row.left == 0
+        assert layout_row.cursor_index == 0
+
     def test_set_cursor_position(self):
         input_data = deque([])
         line_spacing = 1.25
diff --git a/tests/test_core/test_text/test_text_effects.py b/tests/test_core/test_text/test_text_effects.py
index b809c09..d9f5d5a 100644
--- a/tests/test_core/test_text/test_text_effects.py
+++ b/tests/test_core/test_text/test_text_effects.py
@@ -82,6 +82,20 @@ class TestTypingAppearEffect:
 
         assert label.active_text_effect is None
 
+        text_box = UITextBox('<effect id=test>Hell</effect>',
+                             pygame.Rect((10, 10), (200, 100)),
+                             default_ui_manager)
+
+        text_box.set_active_effect(TEXT_EFFECT_TYPING_APPEAR,
+                                   effect_tag='test')
+        text_box.update(time_delta=0.06)
+        text_box.update(time_delta=0.06)
+        text_box.update(time_delta=0.06)
+        text_box.update(time_delta=0.06)
+        text_box.update(time_delta=0.06)
+
+        assert text_box.active_text_chunk_effects == []
+
     def test_has_text_changed(self, _init_pygame, default_ui_manager: UIManager):
         text_box = UITextBox('hello <font color=#FF0000>this is a</font> test',
                              pygame.Rect((10, 10), (200, 100)),
@@ -425,10 +439,11 @@ class TestBounceEffect:
 
         assert effect.bounce_height == 0
 
-        effect.update(time_delta=0.06)
-        effect.update(time_delta=0.06)
+        effect.update(time_delta=0.2)
+        effect.update(time_delta=0.2)
+        effect.update(time_delta=0.2)
 
-        assert effect.bounce_height != 0
+        assert effect.time_acc == 0.0
 
     def test_has_text_changed(self, _init_pygame, default_ui_manager: UIManager):
         text_box = UITextBox('<effect id=test>Hello world</effect>',
@@ -542,10 +557,10 @@ class TestTiltEffect:
 
         assert effect.current_rotation == 0
 
-        effect.update(time_delta=0.06)
-        effect.update(time_delta=0.06)
+        effect.update(time_delta=4.0)
+        effect.update(time_delta=4.0)
 
-        assert effect.current_rotation != 0
+        assert effect.time_acc == 0.0
 
     def test_has_text_changed(self, _init_pygame, default_ui_manager: UIManager):
         text_box = UITextBox('<effect id=test>Hello world</effect>',
@@ -649,10 +664,10 @@ class TestExpandContractEffect:
 
         assert effect.current_scale == 1.0
 
-        text_box.update(time_delta=0.06)
-        text_box.update(time_delta=0.06)
+        text_box.update(time_delta=1.1)
+        text_box.update(time_delta=1.1)
 
-        assert effect.current_scale != 1.0
+        assert effect.time_acc == 0.0
 
     def test_has_text_changed(self, _init_pygame, default_ui_manager: UIManager):
         text_box = UITextBox('<effect id=test>Hello world</effect> other text',
diff --git a/tests/test_windows/test_ui_console_window.py b/tests/test_windows/test_ui_console_window.py
index ea9cf8b..07245c9 100644
--- a/tests/test_windows/test_ui_console_window.py
+++ b/tests/test_windows/test_ui_console_window.py
@@ -9,15 +9,14 @@ from pygame_gui.windows.ui_console_window import UIConsoleWindow
 
 
 class TestUIConsoleWindow:
-    def test_creation(self, _init_pygame, default_ui_manager,
-                      _display_surface_return_none):
-
+    def test_creation(self, _init_pygame, default_ui_manager):
+        pygame.display.set_mode((800, 600))
         UIConsoleWindow(
             rect=pygame.rect.Rect((0, 0), (700, 500)),
             manager=default_ui_manager)
 
-    def test_command_entry_finished(self, _init_pygame, default_ui_manager,
-                                    _display_surface_return_none):
+    def test_command_entry_finished(self, _init_pygame, default_ui_manager):
+        pygame.display.set_mode((800, 600))
         console_window = UIConsoleWindow(rect=pygame.rect.Rect((0, 0), (300, 200)),
                                          manager=default_ui_manager)