From f8e0eb58a664a0dafc30306b79fb6382094212bc Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sat, 15 Nov 2025 23:43:12 +0100 Subject: [PATCH] Fix failing unit tests --- ...test_graphical_animation_deleted_widget.py | 4 +- tests/test_graphical_custom_keyboard.py | 20 +++---- tests/test_graphical_custom_keyboard_basic.py | 52 +++++++++---------- tests/test_graphical_keyboard_animation.py | 36 ++++++------- ...st_graphical_keyboard_method_forwarding.py | 18 +++---- 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/tests/test_graphical_animation_deleted_widget.py b/tests/test_graphical_animation_deleted_widget.py index cde1f540..70e5dd00 100644 --- a/tests/test_graphical_animation_deleted_widget.py +++ b/tests/test_graphical_animation_deleted_widget.py @@ -130,14 +130,14 @@ class TestAnimationDeletedWidget(unittest.TestCase): """ print("Testing keyboard deletion scenario...") - from mpos.ui.keyboard import CustomKeyboard + from mpos.ui.keyboard import MposKeyboard # Create textarea and keyboard (like QuasiNametag does) textarea = lv.textarea(self.screen) textarea.set_size(280, 40) textarea.align(lv.ALIGN.TOP_MID, 0, 10) - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) keyboard.add_flag(lv.obj.FLAG.HIDDEN) diff --git a/tests/test_graphical_custom_keyboard.py b/tests/test_graphical_custom_keyboard.py index cff5e166..5d94af30 100644 --- a/tests/test_graphical_custom_keyboard.py +++ b/tests/test_graphical_custom_keyboard.py @@ -1,5 +1,5 @@ """ -Graphical tests for CustomKeyboard. +Graphical tests for MposKeyboard. Tests keyboard visual appearance, text input via simulated button presses, and mode switching. Captures screenshots for regression testing. @@ -13,15 +13,15 @@ import unittest import lvgl as lv import sys import os -from mpos.ui.keyboard import CustomKeyboard, create_keyboard +from mpos.ui.keyboard import MposKeyboard, create_keyboard from graphical_test_helper import ( wait_for_render, capture_screenshot, ) -class TestGraphicalCustomKeyboard(unittest.TestCase): - """Test suite for CustomKeyboard graphical verification.""" +class TestGraphicalMposKeyboard(unittest.TestCase): + """Test suite for MposKeyboard graphical verification.""" def setUp(self): """Set up test fixtures before each test method.""" @@ -65,7 +65,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): textarea.set_one_line(True) # Create custom keyboard - keyboard = CustomKeyboard(screen) + keyboard = MposKeyboard(screen) keyboard.set_textarea(textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) @@ -114,7 +114,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): screen, keyboard, textarea = self._create_test_keyboard_scene() # Ensure lowercase mode - keyboard.set_mode(CustomKeyboard.MODE_LOWERCASE) + keyboard.set_mode(MposKeyboard.MODE_LOWERCASE) wait_for_render(10) # Capture screenshot @@ -136,7 +136,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): screen, keyboard, textarea = self._create_test_keyboard_scene() # Switch to uppercase mode - keyboard.set_mode(CustomKeyboard.MODE_UPPERCASE) + keyboard.set_mode(MposKeyboard.MODE_UPPERCASE) wait_for_render(10) # Capture screenshot @@ -158,7 +158,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): screen, keyboard, textarea = self._create_test_keyboard_scene() # Switch to numbers mode - keyboard.set_mode(CustomKeyboard.MODE_NUMBERS) + keyboard.set_mode(MposKeyboard.MODE_NUMBERS) wait_for_render(10) # Capture screenshot @@ -180,7 +180,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): screen, keyboard, textarea = self._create_test_keyboard_scene() # Switch to specials mode - keyboard.set_mode(CustomKeyboard.MODE_SPECIALS) + keyboard.set_mode(MposKeyboard.MODE_SPECIALS) wait_for_render(10) # Capture screenshot @@ -248,7 +248,7 @@ class TestGraphicalCustomKeyboard(unittest.TestCase): self.assertFalse( is_white, - f"Custom keyboard buttons are pure white in light mode (invisible)!" + f"Mpos keyboard buttons are pure white in light mode (invisible)!" ) print("=== Visibility test PASSED ===") diff --git a/tests/test_graphical_custom_keyboard_basic.py b/tests/test_graphical_custom_keyboard_basic.py index be67a9c5..d4cbdcd8 100644 --- a/tests/test_graphical_custom_keyboard_basic.py +++ b/tests/test_graphical_custom_keyboard_basic.py @@ -1,5 +1,5 @@ """ -Functional tests for CustomKeyboard. +Functional tests for MposKeyboard. Tests keyboard creation, mode switching, text input, and API compatibility. @@ -10,11 +10,11 @@ Usage: import unittest import lvgl as lv -from mpos.ui.keyboard import CustomKeyboard, create_keyboard +from mpos.ui.keyboard import MposKeyboard, create_keyboard -class TestCustomKeyboard(unittest.TestCase): - """Test suite for CustomKeyboard functionality.""" +class TestMposKeyboard(unittest.TestCase): + """Test suite for MposKeyboard functionality.""" def setUp(self): """Set up test fixtures before each test method.""" @@ -37,10 +37,10 @@ class TestCustomKeyboard(unittest.TestCase): print("=== Test Cleanup Complete ===\n") def test_keyboard_creation(self): - """Test that CustomKeyboard can be created.""" + """Test that MposKeyboard can be created.""" print("Testing keyboard creation...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Verify keyboard exists self.assertIsNotNone(keyboard) @@ -54,10 +54,10 @@ class TestCustomKeyboard(unittest.TestCase): keyboard = create_keyboard(self.screen, custom=True) - # Verify it's a CustomKeyboard instance - self.assertIsInstance(keyboard, CustomKeyboard) + # Verify it's a MposKeyboard instance + self.assertIsInstance(keyboard, MposKeyboard) - print("Factory created CustomKeyboard successfully") + print("Factory created MposKeyboard successfully") def test_keyboard_factory_standard(self): """Test factory function creates standard keyboard.""" @@ -65,9 +65,9 @@ class TestCustomKeyboard(unittest.TestCase): keyboard = create_keyboard(self.screen, custom=False) - # Verify it's an LVGL keyboard (not CustomKeyboard) - self.assertFalse(isinstance(keyboard, CustomKeyboard), - "Factory with custom=False should not create CustomKeyboard") + # Verify it's an LVGL keyboard (not MposKeyboard) + self.assertFalse(isinstance(keyboard, MposKeyboard), + "Factory with custom=False should not create MposKeyboard") # It should be an lv.keyboard instance self.assertEqual(type(keyboard).__name__, 'keyboard') @@ -77,7 +77,7 @@ class TestCustomKeyboard(unittest.TestCase): """Test setting textarea association.""" print("Testing set_textarea...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(self.textarea) # Verify textarea is associated @@ -90,13 +90,13 @@ class TestCustomKeyboard(unittest.TestCase): """Test keyboard mode switching.""" print("Testing mode switching...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Test setting different modes - keyboard.set_mode(CustomKeyboard.MODE_LOWERCASE) - keyboard.set_mode(CustomKeyboard.MODE_UPPERCASE) - keyboard.set_mode(CustomKeyboard.MODE_NUMBERS) - keyboard.set_mode(CustomKeyboard.MODE_SPECIALS) + keyboard.set_mode(MposKeyboard.MODE_LOWERCASE) + keyboard.set_mode(MposKeyboard.MODE_UPPERCASE) + keyboard.set_mode(MposKeyboard.MODE_NUMBERS) + keyboard.set_mode(MposKeyboard.MODE_SPECIALS) print("Mode switching successful") @@ -104,7 +104,7 @@ class TestCustomKeyboard(unittest.TestCase): """Test keyboard alignment.""" print("Testing alignment...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) print("Alignment successful") @@ -113,7 +113,7 @@ class TestCustomKeyboard(unittest.TestCase): """Test height configuration.""" print("Testing height settings...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_style_min_height(160, 0) keyboard.set_style_height(160, 0) @@ -123,7 +123,7 @@ class TestCustomKeyboard(unittest.TestCase): """Test object flags (show/hide).""" print("Testing flags...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Test hiding keyboard.add_flag(lv.obj.FLAG.HIDDEN) @@ -139,7 +139,7 @@ class TestCustomKeyboard(unittest.TestCase): """Test adding event callbacks.""" print("Testing event callbacks...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) callback_called = [False] def test_callback(event): @@ -157,10 +157,10 @@ class TestCustomKeyboard(unittest.TestCase): print("Event callback successful") def test_api_compatibility(self): - """Test that CustomKeyboard has same API as lv.keyboard.""" + """Test that MposKeyboard has same API as lv.keyboard.""" print("Testing API compatibility...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Check that all essential methods exist essential_methods = [ @@ -178,11 +178,11 @@ class TestCustomKeyboard(unittest.TestCase): for method_name in essential_methods: self.assertTrue( hasattr(keyboard, method_name), - f"CustomKeyboard missing method: {method_name}" + f"MposKeyboard missing method: {method_name}" ) self.assertTrue( callable(getattr(keyboard, method_name)), - f"CustomKeyboard.{method_name} is not callable" + f"MposKeyboard.{method_name} is not callable" ) print("API compatibility verified") diff --git a/tests/test_graphical_keyboard_animation.py b/tests/test_graphical_keyboard_animation.py index 0a81770f..050f2f33 100644 --- a/tests/test_graphical_keyboard_animation.py +++ b/tests/test_graphical_keyboard_animation.py @@ -1,7 +1,7 @@ """ -Test CustomKeyboard animation support (show/hide with mpos.ui.anim). +Test MposKeyboard animation support (show/hide with mpos.ui.anim). -This test reproduces the bug where CustomKeyboard is missing methods +This test reproduces the bug where MposKeyboard is missing methods required by mpos.ui.anim.smooth_show() and smooth_hide(). Usage: @@ -12,11 +12,11 @@ Usage: import unittest import lvgl as lv import mpos.ui.anim -from mpos.ui.keyboard import CustomKeyboard +from mpos.ui.keyboard import MposKeyboard class TestKeyboardAnimation(unittest.TestCase): - """Test CustomKeyboard compatibility with animation system.""" + """Test MposKeyboard compatibility with animation system.""" def setUp(self): """Set up test fixtures.""" @@ -40,13 +40,13 @@ class TestKeyboardAnimation(unittest.TestCase): def test_keyboard_has_set_style_opa(self): """ - Test that CustomKeyboard has set_style_opa method. + Test that MposKeyboard has set_style_opa method. This method is required by mpos.ui.anim for fade animations. """ - print("Testing that CustomKeyboard has set_style_opa...") + print("Testing that MposKeyboard has set_style_opa...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(self.textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) keyboard.add_flag(lv.obj.FLAG.HIDDEN) @@ -54,11 +54,11 @@ class TestKeyboardAnimation(unittest.TestCase): # Verify method exists self.assertTrue( hasattr(keyboard, 'set_style_opa'), - "CustomKeyboard missing set_style_opa method" + "MposKeyboard missing set_style_opa method" ) self.assertTrue( callable(getattr(keyboard, 'set_style_opa')), - "CustomKeyboard.set_style_opa is not callable" + "MposKeyboard.set_style_opa is not callable" ) # Try calling it (should not raise AttributeError) @@ -72,13 +72,13 @@ class TestKeyboardAnimation(unittest.TestCase): def test_keyboard_smooth_show(self): """ - Test that CustomKeyboard can be shown with smooth_show animation. + Test that MposKeyboard can be shown with smooth_show animation. This reproduces the actual user interaction in QuasiNametag. """ print("Testing smooth_show animation...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(self.textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) keyboard.add_flag(lv.obj.FLAG.HIDDEN) @@ -89,7 +89,7 @@ class TestKeyboardAnimation(unittest.TestCase): print("smooth_show called successfully") except AttributeError as e: self.fail(f"smooth_show raised AttributeError: {e}\n" - "This is the bug - CustomKeyboard missing animation methods") + "This is the bug - MposKeyboard missing animation methods") # Verify keyboard is no longer hidden self.assertFalse( @@ -101,13 +101,13 @@ class TestKeyboardAnimation(unittest.TestCase): def test_keyboard_smooth_hide(self): """ - Test that CustomKeyboard can be hidden with smooth_hide animation. + Test that MposKeyboard can be hidden with smooth_hide animation. This reproduces the hide behavior in QuasiNametag. """ print("Testing smooth_hide animation...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(self.textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) # Start visible @@ -119,7 +119,7 @@ class TestKeyboardAnimation(unittest.TestCase): print("smooth_hide called successfully") except AttributeError as e: self.fail(f"smooth_hide raised AttributeError: {e}\n" - "This is the bug - CustomKeyboard missing animation methods") + "This is the bug - MposKeyboard missing animation methods") print("=== smooth_hide test PASSED ===") @@ -133,7 +133,7 @@ class TestKeyboardAnimation(unittest.TestCase): """ print("Testing full show/hide cycle...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.set_textarea(self.textarea) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) keyboard.add_flag(lv.obj.FLAG.HIDDEN) @@ -160,13 +160,13 @@ class TestKeyboardAnimation(unittest.TestCase): def test_keyboard_has_get_y_and_set_y(self): """ - Test that CustomKeyboard has get_y and set_y methods. + Test that MposKeyboard has get_y and set_y methods. These are required for slide animations (though not currently used). """ print("Testing get_y and set_y methods...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) keyboard.align(lv.ALIGN.BOTTOM_MID, 0, 0) # Verify methods exist diff --git a/tests/test_graphical_keyboard_method_forwarding.py b/tests/test_graphical_keyboard_method_forwarding.py index 3b222534..ebaafa53 100644 --- a/tests/test_graphical_keyboard_method_forwarding.py +++ b/tests/test_graphical_keyboard_method_forwarding.py @@ -1,8 +1,8 @@ """ -Test that CustomKeyboard forwards all methods to underlying lv.keyboard. +Test that MposKeyboard forwards all methods to underlying lv.keyboard. This demonstrates the __getattr__ magic method works correctly and that -CustomKeyboard supports any LVGL keyboard method without manual wrapping. +MposKeyboard supports any LVGL keyboard method without manual wrapping. Usage: Desktop: ./tests/unittest.sh tests/test_keyboard_method_forwarding.py @@ -10,7 +10,7 @@ Usage: import unittest import lvgl as lv -from mpos.ui.keyboard import CustomKeyboard +from mpos.ui.keyboard import MposKeyboard class TestMethodForwarding(unittest.TestCase): @@ -30,7 +30,7 @@ class TestMethodForwarding(unittest.TestCase): """Test commonly used LVGL methods work via __getattr__.""" print("\nTesting common LVGL methods...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # These should all work without explicit wrapper methods: methods_to_test = [ @@ -58,7 +58,7 @@ class TestMethodForwarding(unittest.TestCase): """Test various style methods work.""" print("\nTesting style methods...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # All these style methods should work: keyboard.set_style_min_height(100, 0) @@ -72,7 +72,7 @@ class TestMethodForwarding(unittest.TestCase): """Test position methods work.""" print("\nTesting position methods...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Position methods: x = keyboard.get_x() @@ -98,7 +98,7 @@ class TestMethodForwarding(unittest.TestCase): """ print("\nTesting that arbitrary LVGL methods work...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) # Try some less common methods: try: @@ -125,10 +125,10 @@ class TestMethodForwarding(unittest.TestCase): """ print("\nTesting that forwarding preserves behavior...") - keyboard = CustomKeyboard(self.screen) + keyboard = MposKeyboard(self.screen) textarea = lv.textarea(self.screen) - # Set textarea through CustomKeyboard + # Set textarea through MposKeyboard keyboard.set_textarea(textarea) # Get it back